I read some socket programming sample code from here. And one question suddenly hits me.
It takes a 4-tuple to construct a TCP socket connection:
<client address, client port, server address, server port>
But it seems only the <server address, server port>
is explicitly specified in both client and server code. And this server port
is only used for listening, not the one actually used by server for communicating.
So who decide the <client address, client port>
? And why not explicitly by the programmer of client code?
ADD1
Correction, seems the bold part above is incorrect. The server port don't change. Ref: Does the port change when a TCP connection is accepted by a server?