Clients Open Connections to Servers
In contrast to server-based applications that are always listening for incoming connections on a fixed port number, client applications will use a randomly assigned port number for their end of the connection. Whenever an IP application needs to send data, the transport protocol will allocate a random port number above 1024 and use this port number for all incoming and outgoing data associated with that application.
For example, when a POP3 client is used to establish a connection with a mail server, the client application will pass an application-specific command to TCP, specifying the server’s IP address and port number as the destination. TCP will then add its own information—including stuff like the port number of the local POP3 client—and hand the entire package off to IP for delivery. IP then does its best to get the message to the destination system.
When the mail server’s IP stack receives the datagram, it verifies that it contains a TCP segment, and then hands the contents off to TCP for further processing. TCP will see that the destination port number refers to the local POP3 server, and then hand off the original application command. Once the server has processed the command, it will reverse the process, sending whatever data it generates back to the port number and IP address in use by the client. Once the transaction is finished, the client’s TCP port will be released. Any subsequent connections would require a new connection be opened, ...