This section covers how both TCP and UDP use port numbers to identify the proper application layer process.
Multiple Separate Communications (26.4.1)
As you have learned, there are some situations in which TCP is the right protocol for the job, and other situations in which UDP should be used. No matter what type of data is being transported, the TCP and UDP transport layer protocols use port numbers to manage multiple, simultaneous conversations. As shown in Figure 26-13, the TCP and UDP header fields identify a source application port number and a destination application port number.
Figure 26-13 Source and Destination Port Fields
The source port number is associated with the originating application on the local host, whereas the destination port number is associated with the destination application on the remote host.
For instance, when a host initiates a web page request from a web server, the source port number is dynamically generated by the host to uniquely identify the conversation. Each request generated by a host uses a different dynamically created source port number. This process allows multiple conversations to occur simultaneously.
In the request, the destination port number identifies the type of service being requested of the destination web server. For example, when a client specifies port 80 in the destination port, the server that receives the message knows that web services are being requested.
A server can offer more than one service simultaneously, such as web services on port 80 and File Transfer Protocol (FTP) connection establishment on port 21.
The source and destination ports are placed within the segment. The segments are then encapsulated within an IP packet. The IP packet contains the IP addresses of the source and destination. The combination of the source IP address and source port number, or the destination IP address and destination port number, is known as a socket.
In the example in Figure 26-14, the PC is simultaneously requesting FTP and web services from the destination server.
Figure 26-14 Host Sending Multiple Simultaneous Communications
In Figure 26-14, the FTP request generated by the PC includes the Layer 2 MAC addresses and the Layer 3 IP addresses. The request also identifies the source port number 1305 (dynamically generated by the host) and destination port, identifying the FTP services on port 21. The host also has requested a web page from the server using the same Layer 2 and Layer 3 addresses. However, it is using the source port number 1099 (dynamically generated by the host) and destination port identifying the web service on port 80.
The socket is used to identify the server and service being requested by the client. A client socket might look like this, with 1099 representing the source port number: 192.168.1.5:1099.
The socket on a web server might be 192.168.1.7:80.
Together, these two sockets combine to form a socket pair: 192.168.1.5:1099, 192.168.1.7:80.
Sockets enable multiple processes, running on a client, to distinguish themselves from each other, and enable multiple connections to a server process to be distinguished from each other.
The source port number acts as a return address for the requesting application. The transport layer keeps track of this port and the application that initiated the request so that when a response is returned, it can be forwarded to the correct application.