Determine dynamically assigned port of accepted server socket

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

After a server accepts a client connection on a certain port, a new socket is
created on the server on a system managed dynamic port to handle the
connection. Please confirm this.

If so, how can I get the number of the dynamic port in the server (in server
code)? Using LocalEndPoint.Port just returns the original listener port
number.

Thanks,

Jason
 
No, I don't need the client's port number, I need the server's new port
number for that instance socket.

Jason
 
Hi,

Jason said:
After a server accepts a client connection on a certain port, a new socket
is
created on the server on a system managed dynamic port to handle the
connection. Please confirm this.

No, that's not true. It creates a new Socket but keeps using the same port.
A TCP server can have multiple client connections to the same port.


HTH,
Greetings
 
Well then how does the server (underneath) resolve which socket steam should
recieve incoming packets? I thought this was done by creating the instance
socket on the server with a new port in the system managed dynamic port range.

Thanks,

Jason
 
Hi,

Jason said:
Well then how does the server (underneath) resolve which socket steam
should
recieve incoming packets?

When there are multiple connections to the same server ip and server port ,
then either the client's ip or client's port is different or both.
Underneath it not only uses server ip and port but also client ip and port
to resolve the right Socket.
I thought this was done by creating the instance
socket on the server with a new port in the system managed dynamic port
range.

No, it's not, if you use windows you can use the commandline tool 'netstat'
to see that the _same_ server port is used when you have accepted a number
of connections.

For detailed explaining i can only recommend reading the RFC's about the TCP
protocol.

hth,
Greetings
 
Back
Top