The Transport layer of the TCP/IP protocol suite consists of two protocols, UDP and TCP. UDP provides an unreliable connectionless delivery service to send and receive messages. TCP adds reliable byte stream-delivery services on top of the IP datagram delivery service.
The ports numbered between 1 and 1,023 are well-known port numbers. For dynamically bound ports, an application requests that UDP assign a port to identify which port the process uses. The port must be in the range of 1,024 to 65,535.
UDP identifies applications through ports. The protocol defines two types of protocol ports: well-known port assignments and dynamically bound ports. For well-known port assignments, certain UDP port numbers are reserved for particular applications. Then the application can direct UDP datagrams to that port.
UDP enables multiple clients to use the same port number and different IP addresses. The arriving UDP datagrams are delivered to the client that matches both the destination port number and address. (A socket consists of an IP address and the port number.) If there is no matching client or if the ICMP destination is unreachable then a port unreachable message is sent and the packet is dropped.
The UDP datagram is encapsulated in an IP datagram that, in turn, is encapsulated in physical frames. Figure 1-3 shows a UDP datagram encapsulated in an IP datagram, which, in turn, is encapsulated in an Ethernet frame. This figure also illustrates how the concept of layering, discussed at the beginning of this section, affects the construction of packets sent across the network.
Figure 1-3 UDP Datagram Encapsulation
In this example, the IP address transmits the IP datagram to the node. At that destination, the IP software extracts the UDP datagram and delivers it to the UDP-layer software. The UDP-layer software delivers the UDP data through the destination port to the receiving application. The process at that port uses the data in the UDP datagram. The UDP datagram also contains a source port to ensure that the destination process can reply correctly.
For applications that must send or receive large volumes of data, unreliable datagram delivery can become burdensome. Application programmers might need to develop extensive error handling and status information modules to track the progress and state of data transfer for every application. The TCP/IP suite of protocols avoids this problem by using TCP, a reliable byte-stream delivery protocol. TCP establishes a connection between two applications and sends a stream of bytes to a destination in exactly the same order that they left the source. Before transmission begins, the applications at both ends of the transmission obtain a TCP port from their respective operating systems. These are analogous to the ports used by UDP. The application initiating the transfer, known as the client side, generally obtains a port dynamically. The application responding to the transfer request, known as the server side, generally uses a well-known TCP port. The client side is typically the active side and initiates the connection to the passive server side.
Like the UDP datagrams, TCP segments are encapsulated in an IP datagram. TCP buffers the stream by waiting for enough data to fill a large datagram before sending the datagram. The stream is unstructured, which means that before transmission of data, both the sending and receiving applications must agree on the meaning of the contents of the stream. The TCP protocol uses full-duplex transmission. Full duplex means that two data streams can flow in opposite directions simultaneously. Thus, the receiving application can send data or control information back to the sending application while the sending application continues to send data.
The TCP protocol gives each segment a sequence number. At the receiving end of the connection, TCP checks successive sequence numbers to ensure that all the segments are received and processed in the order of the sequence numbers. The receiving end sends an acknowledgment to the sender for the segments received. TCP enables the sender to have several outstanding segments before the receiver must return an acknowledgment. If the sending node does not receive an acknowledgment for a segment within a certain time, it retransmits that segment. This scheme, called positive acknowledgment with retransmission, ensures that the stream delivery is reliable.