Open In App

Services and Segment structure in TCP

The Transmission Control Protocol is the most common transport layer protocol. It works together with IP and provides a reliable transport service between processes using the network layer service provided by the IP protocol. 
The various services provided by the TCP to the application layer are as follows: 
 

  1. Process-to-Process Communication – 
    TCP provides a process to process communication, i.e, the transfer of data that takes place between individual processes executing on end systems. This is done using port numbers or port addresses. Port numbers are 16 bits long that help identify which process is sending or receiving data on a host. 
     
  2. Stream oriented – 
    This means that the data is sent and received as a stream of bytes(unlike UDP or IP that divides the bits into datagrams or packets). However, the network layer, that provides service for the TCP, sends packets of information not streams of bytes. Hence, TCP groups a number of bytes together into a segment and adds a header to each of these segments and then delivers these segments to the network layer. At the network layer, each of these segments is encapsulated in an IP packet for transmission. The TCP header has information that is required for control purposes which will be discussed along with the segment structure. 
     
  3. Full-duplex service – 
    This means that the communication can take place in both directions at the same time. 
     
  4. Connection-oriented service – 
    Unlike UDP, TCP provides a connection-oriented service. It defines 3 different phases: 
    • Connection establishment
    • Data transfer
    • Connection termination
  5. Reliability – 
    TCP is reliable as it uses checksum for error detection, attempts to recover lost or corrupted packets by re-transmission, acknowledgement policy and timers. It uses features like byte number and sequence number and acknowledgement number so as to ensure reliability. Also, it uses congestion control mechanisms. 
     
  6. Multiplexing – 
    TCP does multiplexing and de-multiplexing at the sender and receiver ends respectively as a number of logical connections can be established between port numbers over a physical connection. 
     

Byte number, Sequence number and Acknowledgement number: 
All the data bytes that are to be transmitted are numbered and the beginning of this numbering is arbitrary. Sequence numbers are given to the segments so as to reassemble the bytes at the receiver end even if they arrive in a different order. The sequence number of a segment is the byte number of the first byte that is being sent. The acknowledgement number is required since TCP provides full-duplex service. The acknowledgement number is the next byte number that the receiver expects to receive which also provides acknowledgement for receiving the previous bytes. 
Example: 



 



In this example we see that A sends acknowledgement number1001, which means that it has received data bytes till byte number 1000 and expects to receive 1001 next, hence B next sends data bytes starting from 1001. Similarly, since B has received data bytes till byte number 13001 after the first data transfer from A to B, therefore B sends acknowledgement number 13002, the byte number that it expects to receive from A next. 

TCP Segment structure – 
A TCP segment consists of data bytes to be sent and a header that is added to the data by TCP as shown: 

 

The header of a TCP segment can range from 20-60 bytes. 40 bytes are for options. If there are no options, a header is 20 bytes else it can be of upmost 60 bytes. 
Header fields: 
 

TCP Connection – 
TCP is connection-oriented. A TCP connection is established by a 3-way handshake.

Article Tags :