Does the port change when a server accepts a TCP connection?

zooropa picture zooropa · Jun 8, 2010 · Viewed 15.6k times · Source

When a client connects to a server using TCP, a new socket is created for the TCP stream. Does the connection remain on the same port the connection was made or does it get changed to some other port?

Answer

Marcelo Cantos picture Marcelo Cantos · Jun 8, 2010

The new socket is an application-level concept introduced because each established connection needs a unique file descriptor (also distinct from the listening file descriptor), which maps to, but isn't the same as, a TCP session. The session itself is identified by the combination of source and destination address and port. The source (client) port is usually chosen at random, while the destination (server) port is the listen port. No additional port is allocated.