Patrick wrote:

>> How can I control what port is used by the socket returned by the accept
> method? (As you all know, after the server accepts a client connection, it
> creates a *brand new socket* which listens on *a brand new port*; this is so
> the server can continue listening to more clinet connections on the original
> socket...).


Let's get this straight. accept() does in fact create a brand new 
socket, but this new socket does *NOT* listen on a brand new port. If 
your server socket is listening on port 9001, the socket you get back 
from accept() will also be on local port 9001. But then how can the 
server continue to  listen for more client connections on the original 
socket? Because it can still differentiate between the sockets by 
looking at the remote (client) port. Your server may have tens or 
hundreds of sockets running off port 9001 simultaneously, but each one 
will be talking to a different remote address/port.  Run netstat on your 
server sometime to see this.


Reply via email to