Skip to content
Related Articles

Related Articles

Why TCP Connect Termination Need 4-Way-Handshake?

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 19 Apr, 2022

The modern developments in everyday life, in terms of technology and the internet, are only made possible with the help of the TCP/IP suite. 

TCP is been used for communication among devices on the network. It stands for Transmission Control Protocol. It can work with any type of network, whether personal networks or the internet. For instance, it can work with the extranet or intranet, etc.

In short, TCP simply determines the data transfer in the network. TCP works by breaking the data into small packets which can be transferred through network activity. 

Let’s understand it with an example, suppose, the client needs to send some data to the server, it will be sent through a TCP. It is used to create a connection between the client and the server. Once the connection is successfully established and the data is transferred to the server. Thus, the next step will be to close the connection. 

Here in this article, we will be discussing the importance of TCP in computer networking and the TCP connection establishment and termination. Mainly, we will discuss the Four-Way Handshake process, its importance, advantages, and disadvantages.

TCP Connection Establishment Process

TCP is a connection-oriented protocol, which works in terms of full-duplex mode. So, the very first thing is that it requires a well-established logical connection between the devices so that data can be exchanged. Here the noticeable thing is that it can send data to both sides.

So, here are the main 3 steps, also known as TCP 3-way Handshake, which required to fully establish the TCP connection is given below:

  1. In the first step, on the one side, either client or the server initiates the connection establishment by sending “synchronize” or an SYN flag to the other side. In this step, the client’s initial sequence number will be sent to the server to create a connection.
  2. In return for the SYN flag, the TCP server will send an “Acknowledgement” or ACK flag along with its initial sequence number for the connection establishment.
  3. And finally, with the client’s confirmation through the ACK flag, in return to the server’s SYN flag, the connection establishment will be activated. 

Now, to understand the process clearly, here we will be discussing the further steps to establish the TCP connection down below:

In the first step, the client sends an SYN request to establish a connection, as the Packet SYN: 1 to the server. After successfully receiving the SYN flag or the packet, now the server will send an ACK flag as the packet ACK: 1 for the confirmation purpose to the client. In the process, the server can also send the data to the other side. For this, the server will be sending the data as the packet SYN: 1 along to the client. Finally, after receiving the data successfully, the client will then send an ACK flag as packet ACK: 1 to the server as a confirmation. 

To understand it you can also take a look at the given diagram below:
 

The Three-Way Connection Establishment

The Three-Way Connection Establishment

The Four-way Handshake or TCP Connection Termination:

Here, to terminate an established TCP connection, the following 4 TCP packets are needed to be exchanged. Which you can understand with the statements below:

1. Host A → Host B: FIN flag set.
2. Host B → Host A: ACK flag set.
3. Host B → Host A: FIN flag set.
4. Host A → Host B: ACK flag set.

These 4 steps are known as a TCP 4-way handshake, which is necessary to terminate a TCP connection. For the termination of the established TCP connection, the following steps are necessary for the process. Which are given down below:

  1. Firstly, from one side of the connection, either from the client or the server the FIN flag will be sent as the request for the termination of the connection.
  2. In the second step, whoever receives the FIN flag will then be sending an ACK flag as the acknowledgment for the closing request to the other side.
  3. And, at the Later step, the server will also send a FIN flag as the closing signal to the other side.
  4. In the final step, the TCP, who received the final FIN flag, will be sending an ACK flag as the final Acknowledgement for the suggested connection closing.

Since the Four main steps are required to close an active connection, so, it is called a four-way handshake. For a better understanding, you can take a look at the diagram below:
 

The Four-Way Handshake Process

The Four-Way Handshake Process

Why Does TCP Connect Termination Need 4-way-Handshake?

Now the question is, why termination can not send ACK and FIN packets at once? By which one step can be reduced. And why the four-way handshake is necessary here?

Well, by looking at it carefully, it can be seen that the four-way Handshake is actually a set of two-way handshakes. However, it is not completely false that in some cases, the 2 and 3 can be set at the same packet.

The four-way handshake works as a pair of two-way Handshakes. Where, the first phase is, when the client sends the FIN flag to the server, and in return, the server sends the ACK flag as acknowledgment. 

This can be understood by the statement below:

Client ------FIN-----> Server
Client <-----ACK------ Server

At this point, the client is in the waiting state, it is waiting for the FIN flag from the server. So, that the connection can be terminated. This state can be mentioned as FIN_WAIT_2. 

Now as we know that it works as the full-duplex mode, so if the one-side connection is broken down, then no more data can be sent from that side of the connection. But it can still receive the data from another side. 

Here, the server can send more data when the Client is in the FIN_WAIT_2 state. And once the server is done sending data, then the server will send the FIN flag to the client as the termination request, and then the client sends the ACK flag as the confirmation to terminate the connection. 

As you can see in the statement below:

Client <-----FIN------ Server
Client ------ACK-----> Server

So, as explained, in this case, steps 2 and 3 cannot be sent as one package, since they belong to two different states. 

Here four-way handshake is necessary in this case, as the first FIN flag, that is sent to the server by the client is a request for termination. And the first ACK, received by the client is just a response to FIN 1. Now here only the connection from the client is disconnected, but the server is still in a working position. This means it may still have some data to send. So, in this condition, the connection cannot be cut down suddenly. here, the other two steps are needed to be performed by the server. 

Now the other reason is that it can become difficult for both sides to define why the peer does not respond. Also, not only the offline state can cause a packet lost. Alongside, the other exceptions in the server’s processing can also lead to it. And there is another problem with this idea is that in this condition, the client will have to wait for a long time until the time is out. Here, the four-way handshake looks like a better and easier option to address these problems.

Advantages of using TCP

Here, some of the advantages of using TCP connections are given below:

  • It’s a secure way of transferring data, as it requires confirmations at each step before sending any data. 
  • It can be used in many different fields related to computer networking.  
  • It can communicate across a variety of different networks such as protocols, etc.
  • Because of its scalability, more devices can be added and withdrawn easily. 
  • In the matter of security, it helps to identify each device on the network by IP address, which helps improve the network security. the IP address can be used to identify the device.

Disadvantages of using TCP:

Here are some of the downfalls of using TCP. Which is given below:

  • It is not capable of representing the other protocols accept in TCP/IP suite like in the other Bluetooth connections.
  • The line between the concept of services, interfaces, and protocols is unclear.
  • Other than that, it’s a time-consuming process, since it involves many steps. And also, the connection cannot be closed without getting the FIN flags along with the ACK flags as a confirmation from both sides, which takes time.

So far, we’ve talked about the role of TCP in computer networking. The process of establishing a network connection and terminating it via the Four-way handshake. In conclusion, despite its limitations, it is an efficient method of transferring data between networks.


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!