Hurry! Try our new Interactive Courses for FREE. 🥳   🚀

TCP - Transmission Control Protocol

In this tutorial, we will be covering another protocol of the transport layer in Computer Networks.

TCP is an abbreviation of Transmission Control Protocol. This is a Transport Layer Protocol.TCP is a connection-oriented protocol. It is a reliable protocol used for transport. This protocol adds connection-oriented and reliability features to the services of the Internet Protocol.

This protocol seeks to deliver a stream of bytes from end-to-end in a particular order.

As it is the responsibility of the transport layer to provide end-to-end communication, thus TCP plays a very important role in the transport layer.

Features of Transmission Control Protocol

Given below are the features of TCP let us take a look at them:

1.Numbering System

There are two fields in TCP mainly sequence number and acknowledgment number. These two fields in the TCP mainly refers to Byte Number.

  • Byte Number
    The bytes of data that are being transferred in each connection are numbered by TCP. The numbering mainly starts with a randomly generated number.

    • TCP mainly numbers all the data bytes that are transmitted in a connection.

    • It generates a random number between 0 and 2 raised to the power of 32 -1 for the number of the first byte.

    • Example: If the random no. is 1056 and there are a total of 6000 bytes to be sent then the bytes are numbered from 1056 to 7055.

  • Sequence Number
    After the numbering of bytes, the TCP makes the grouping of bytes in the form of "segments".

    • A sequence is assigned to each segment that is being sent.

    • The Sequence number of each segment is the number of the first byte that is carried in that segment.

    • Thus the value in the sequence number field of the segment mainly defines the number of the first data byte that is contained in that segment.

  • Acknowledgment Number
    The value of the acknowledgment field in the segment mainly defines the number of the next byte that a party mainly expects to receive.

    • It is cumulative in nature.

2.Flow Control

The TCP provides the facility of Flow control. With the help of TCP, the receiver of the data control the amount of the data that are to be sent by the sender.

  • The flow control is mainly done in order to prevent the receiver from being overwhelmed with the data

  • The numbering system also allows the TCP to use byte-oriented flow control.

3.Error Control

As TCP provides reliable services, thus it implements an error control mechanism for this purpose. The Error control though considers the segment as the unit of data for error detection. Error control is byte-oriented in nature.

4.Congestion Control

Another main feature of TCP is that it facilitates Congestion Control in the network. The Amount of the data that the sender sends is not only controlled by the receiver, but congestion in the network also determines it.

5.Full Duplex

TCP provides another feature and that is Full Duplex which means by using TCP the data can be transmitted in both directions.

6.TCP is a transport layer protocol because it is mainly used to transmit the data from the sender to the receiver.

Now before moving on to the further concepts let us take a look at the TCP packet.

Segment

The packet in the TCP is mainly known as a segment.

Format

Given below is the format of the TCP packet let us take a look at it:

The Segment mainly consists of a 20- to 60-byte header that is followed by the application program. Usually, the header is 20 bytes but sometimes in case if there are no options then it goes up to 60 bytes if it contains many options.

  • Source Port Address
    It is a 16-bit field and is mainly defines the port number of the application program in the host that is mainly used for sending the segment. The purpose of the Source port address is the same as the source port address in the header of the UDP.

  • Destination Port Address
    This is also a 16-bit address and is mainly defines the port number of the application program in the host that is mainly used for receiving the segment. The purpose of the Destination port address is the same as the destination port address in the header of the UDP.

  • Sequence Number
    It is a 32-bit field that mainly defines the number assigned to the first byte of data that is contained in the segment.

  • Acknowledgment Number
    It is also a 32-bit field and is mainly used to define the byte number that the receiver of the segment is expecting to receive from the other party.

  • Header Length
    It is a 4-bit field and is mainly used to indicate the number of 4-byte words in the TCP header. The length of the header lies between 20 and 60 bytes.

  • Reserved
    It is a 6-bit field and is mainly reserved for future use.

  • Control
    This field mainly defines 6 different control bits or flags and among all only one can be set at that time.

These bits mainly enables the flow control, connection establishment, termination, and modes of transferring the data in TCP.

  • Window Size
    This field is mainly used to define the size of the window. The size of this field is 16-bit. It mainly contains the size of the data the receiver can accept. The value of this field is mainly determined by the receiver.

  • Checksum
    It is a 16-bit field and is mainly contains the checksum. This field is mandatory in the case of TCP/IP.

  • Urgent Pointer
    The size of this field is 16-bit and it is only valid in the case if the urgent flag is set. This field is used only when the segment contains urgent data.

  • Options
    This field is represented in 32 bits.

TCP Connection

As we know that TCP is a connection-oriented protocol and it means this protocol establishes a virtual path between the source and the destination. All the segments that belong to the message are then sent over this virtual path.

In TCP, the connection-oriented transmission mainly requires three phases and these phases are:

  • Connection Establishment Phase

  • Data Transfer Phase

  • Connection Termination.

Connection Establishment Phase

Transmission of data is done in full-duplex mode. The connection establishment in TCP is mainly termed as three-way handshaking. Let us understand this with the help of an example: An application program called client wants to make a connection with another application program called server by using the TCP as the transport layer protocol.

Mainly the process starts with the server, the server program mainly tells the TCP that it is ready to accept a connection. This is mainly known as a request for a passive open. Though the server TCP is ready to accept any connection from any machine of the world and it cannot make the connection itself.

SYN

  • This flag is used for the synchronization of sequence numbers.

  • It does not carry any real data.

  • It mainly consumes 1 sequence number.

SYN+ACK

  • This is mainly used for synchronization in other directions and ACK for the signal received.

  • It does not carry any real data.

  • It also consumes 1 sequence number.

ACK

  • It is just an ACK segment.

  • It does not consume any sequence number if it does not carry any data.

Data Transfer Phase

After the establishment of the connection, the bidirectional data transfer can take place. Both the client and server can send data and acknowledgments.

Connection Termination Phase

The two parties that are involved in the data exchange can close the connection, although it is initiated usually by the client. There ate two ways for the connection termination:

  • Three-way handshaking

  • four-way handshaking with a half close option.

Figure shows Connection Termination using three-way handshaking

FIN

  • This segment consumes one sequence number if it does not carries any data.

  • It may or may not carries any real data.

FIN+ACK

  • This segment consumes consequence numbers if it does not carries any data.

  • The FIN segment announces the closing of the connection in another direction.

  • ACK is for received FIN.

  • It consumes only 1 sequence number.

ACK

  • It is just an ACK segment.

  • It does not consume any sequence number.

Advantages of TCP

Given below are some of the advantages of TCP:

1.TCP performs data control and flow control mechanisms.

2.TCP provides excellent support for cross-platform.

3.The TCP protocol ensures the guaranteed delivery of the data.

4.It transmits the data from the sender to the receiver in a particular order.

5.It is a connection-oriented and reliable protocol.

6.It has a good relative throughput on the modem or on the LAN.

7.Provides error detection mechanism by using the checksum and error correction mechanism is provided by using ARP or go-back protocol.

Disadvantages of TCP

Given below are the disadvantages of TCP:

1.It cannot be used for broadcast or multicast transmission.

2.There is an increase in the amount of overhead.