Peter Osucha <[EMAIL PROTECTED]> wrote: > How does the 'TCP Stack' 'do it for me' on the varying the ports thing.
Ports are like doors, IP addresses are like house addresses. Your machine has usually only one house address (unless it is multi-homed - i.e. has more than one network adapter), but has 65536 doors - ports (actually it's less than this, but that doesn't matter). If you're trying to exit your house to go somewhere else, it doesn't matter which door you leave through; but if you're expecting someone to visit, and similarly if you're going to visit someone else, it's a big help to know which door to listen to / knock on. This is why the port really only matters for the listening (server) side and not for the client side. > Mike's comment on multiple windows in a browser made some sense. > However, when I am setting up a Socket object under Net 2.0 to handle > this connection, I create it by using a object of type IPEndPoint in > which I specific the IP Address and port number. > > _ipHost = Dns.GetHostEntry ( hostIPEndPoint.Address ); > _port = hostIPEndPoint.Port; > _socket = new Socket ( AddressFamily.InterNetwork, > SocketType.Stream, > ProtocolType.Tcp ); > lock ( _socket ) > _socket.Connect ( hostIPEndPoint ); Here, you are passing the target IP address:port endpoint to Socket.Connect. The TCP/IP stack will try to figure out what network interface to use based on the target IP address (these are configured with OS routing if your system is multi-homed), and will pick a more or less random port on that interface while it tries to connect to the target IP address:port. The varying port only affects the client side, the side making the connection. The port you're passing to Socket.Connect is the target port, not the client-side port. -- Barry -- http://barrkel.blogspot.com/ =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com