Transport Layer Protocols

Two protocols exist for the transport layer: TCP and UDP. Both TCP and UDP lie between the application layer and the network layer. As a network layer protocol, IP is responsible for host-to-host communication at the computer level, whereas TCP or UDP is responsible for process-to-process communication at the transport layer.

Transmission Control Protocol (TCP)

TCP provides a connection-oriented byte stream service, which means two end points (normally a client and a server) communicating with each other on a TCP connection. TCP is responsible for flow/error controls and delivering the error-free datagram to the receiving application program.

TCP needs two identifiers, IP address and port number, for a client/server to make a connection offering a full-duplex service. To use the services of TCP, the client socket address and server socket address are needed for the client/server application programs.

The sending TCP accepts a datagram from the sending application program, creates segments (or packets) extracted from the datagram, and sends them across the network. The receiving TCP receives packets, extracts data from them, orders them if they arrived out of order, and delivers them as a byte stream (datagram) to the receiving application program.

TCP header

TCP data is encapsulated in an IP datagram. The TCP packet (or segment) consists of a 20–60-byte header, followed by data from the application program. The header is 20 bytes if there is no option and up to 60 bytes if it contains some options.

  • Source and destination port numbers (16 bits each): Each TCP segment contains a 16-bit field each that defines the source and destination port number to identify the sending and receiving application. These two port numbers, along with the source and destination IP addresses in the IP header, uniquely identify each connection.

The combination of an IP address and a port number is sometimes called a socket. The socket pair, consisting of the client IP address and port number and the server IP address and port number, specifies two end points that uniquely identify each TCP connection in the Internet.

  • Sequence number (32 bits): This 32-bit sequence field defines the sequence number assigned to the first byte of data stream contained in this segment. To ensure connectivity, each byte to be transmitted is numbered. This sequence number identifies the byte in the data stream from the sending TCP to the receiving TCP.

Considering the stream of bytes following in one direction between two applications, TCP will number each byte with a sequence number. During connection establishment, each party uses a random number generator to create an initial sequence number (ISN) that is usually different in each direction.

The 32-bit sequence number is an unsigned number that wraps back around to 0 after reaching 232 − 1.

  • Acknowledgement number (32 bits): This 32-bit field defines the byte number that the sender of the segment is expecting to receive from the receiver. Since TCP provides a full-duplex service to the application layer, data can flow in each direction, independent of the other direction.

The sequence number refers to the stream flowing in the same direction as the segment, while the acknowledgement number refers to the stream flowing in the opposite direction from the segment. Therefore, the acknowledgement number is the sequence number plus 1 of the last successfully received byte of data. This field is only valid if the ACK flag is on.

  • Header length (4 bits): This field indicates the number of four-byte words in the TCP header. Since the header length is between 20 to 60 bytes, an integer value of this field can be between 5 and 15, because 5 × 4 = 20 bytes and 15 × 4 = 60 bytes.
  • Reserved (6 bits): This is a six-bit field reserved for future use.
  • Code bits (6 bits): There are six flag bits (or control bits) in the TCP header. One or more can be turned on at the same time. Below is a brief description of each flag to determine the purpose and contents of the segment.

URG - The urgent point field is valid.
ACK - The acknowledgement number is valid.
PSH - This segment requests a push.
RST - Reset the connection.
SYN - Synchronise sequence number to initiate a connection.
FIN - The sender is finished sending data.

  • Window size (16 bits): This 16-bit field defines the size of window in bytes. Since the window size of this field is 16 bits, the maximum size of the window is 216 − 1 = 65 535 bytes. TCP’s flow control is provided by each end, advertising a window size. This is the number of bytes, starting with the one specified by the acknowledgement number field, that the receiver is willing to accept.
  • Checksum (16 bits): This 16-bit field contains the checksum. The checksum covers the TCP segment, TCP header and TCP data. This is a mandatory field that must be calculated and stored by the sender, and then verified by the receiver.
  • Urgent pointer (16 bits): This 16-bit field is valid only if the URG flag is set. The urgent point is used when the segment contains urgent data. It defines the number that must be added to the sequence number to obtain the number of the last urgent byte in the data section of the segment.
  • Options (24 bits): The options field (if any) varies in length, depending on which options have been included. The size of the TCP header varies depending on the options selected. The TCP header can have up to 40 bytes of optional information.

The options are used to convey additional information to the destination or to align other options. The options are classified into two categories: one-byte options contain end of option and no operation; multiple-byte operations contain maximum segment size, window scale factor and timestamp.

TCP is a connection-oriented byte stream transport layer protocol in the TCP/IP suite. TCP provides a full duplex connection between two applications, allowing them to exchange large volumes of data efficiently. Since TCP provides flow control, it allows systems of widely varying speeds to communicate.

To accomplish flow control, TCP uses a sliding window protocol so that it can make efficient use of the network. Error detection is handled by the checksum, acknowledgement and timeout. TCP is used by many popular applications such as HTTP (World Wide Web), TELNET, Rlogin, FTP and SMTP for e-mail.

User Datagram Protocol (UDP)

UDP lies between the application layer and IP layer. Like TCP, UDP serves as the intermediary between the application programs and network operations. UDP uses port numbers to accomplish a process-to-process communication. The UDP provides a flow-and-control mechanism at the transport level.

In fact, it performs very limited error checking. UDP can only receive a data unit from the process, and deliver it to the receiver unreliably. The data unit must be small enough to fit in a UDP packet. If a process wants to send a small message and does not care much about reliability, it will use UDP.

UDP is a connectionless protocol. It is often used for broadcast-type protocols, such as audio or video traffic. It is quicker and uses less bandwidth because a UDP connection is not continuously maintained. This protocol does not guarantee delivery of information, nor does it repeat a corrupted transfer, as does TCP.