Establishing and Releasing Connection in Transport Layer

ESTABLISHING AND RELEASING CONNECTION IN TCP

TCP provides us with a secure and reliable connection link between two devices. And, this is possible only due to the 3-way handshake process that takes place in the TCP during establishing and closing connections between two devices. As the name suggests, there are three steps for both establishing and closing the connection.

 

The 3-Way Handshake process is the defined set of steps that takes place in the TCP for creating a secure and reliable communication link and also closing it. Actually, TCP uses the 3-way handshake process to establish a connection between two devices before transmitting the data. After the establishment of the connection, the data transfer takes place between the devices. After which the connection needs to be terminated, which is also done by using the 3-way handshake process. The secure and reliable connection is established to reserve the CPU, buffer, and bandwidth of the devices to communicate properly. Thus, it is a must to free these resources by terminating the connection after data transmission. Hence, the TCP 3-way handshake process can be used to establish and terminate connections in the network in a secure way.

 

  1. SYN Flag: SYN stands for synchronization. It can be described as a request for establishing a connection. If SYN is 1, it means that the device wants to establish a secure connection, else not.
  2. ACK Flag: ACK stands for acknowledgement. It can be described as the response of SYN. If ACK is 1, the device has received the SYN message and acknowledges it, else not.
  3. FIN Flag: FIN stands for Finished. After the data transmission has been completed, devices have to terminate the connection using the FIN flag. If FIN is 1, the device wants to terminate the connection, else not.

ESTANBLISHING CONNECTION

Below is the pictorial representation of the connection establishment using the 3-way handshake process.

Following are the three steps involved in establishing the connection using the 3-way handshake process in TCP:

  1. The client sends the SYN to the server: When the client wants to connect to the server. It sets the 'SYN' flag as 1 and sends the message to the server. The message also has some additional information like the sequence number(any random 32 bits number), the ACK is set here to 0, the window size, and the maximum segment size. 
  2. The server replies with the SYN and the ACK to the client: After receiving the client's synchronization request, the server sends an acknowledgement to the client by setting the ACK flag to '1'. The acknowledgement number of the ACK is one more than the received sequence number.
  3. The client sends the ACK to the server: After receiving the SYN from the server, the client sets the ACK flag to '1' and sends it with an acknowledgement number 1 greater than the server's SYN sequence number to the client. Here, the SYN flag is kept '0'. 
  4. After completion of this step, the connection is now established from the server to the client-side also. After the connection is established, the minimum of the sender's and receiver's maximum segment size is taken under consideration for data transmission.

TERMINATING CONNECTION

Below is the pictorial representation of the connection termination using the 3-way handshake process.

 

Following are the three steps involved in terminating the connection using the 3-way handshake process in TCP:

  1. The client sends the FIN to the server: When the client wants to terminate the connection. It sets the FIN flag as '1' and sends the message to the server with a random sequence number. Here, the ACK is set to 0.
  2. The server replies with the FIN and the ACK to the client: After receiving the client's termination request, the server sends an acknowledgement to the client by setting the ACK flag to '1'. The acknowledgement number of the ACK is one more than the received sequence number. For Example, if the client has sent the FIN with sequence number = 1000, then the server will send the ACK with acknowledgement number = 1001. Also, the server sets the FIN flag to '1' and sends it to the client, if the server also wants to terminate the connection. The sequence number used here for the FIN will be different from the client's FIN. After completion of this step, the connection is terminated from the client to the server-side.
  3. The client sends the ACK to the server: After receiving the FIN from the server, the client sets the ACK flag to '1' and sends it with an acknowledgement number 1 greater than the server's FIN sequence number to the client. Here, the FIN flag is kept '0'. After completion of this step, the connection is now terminated from the server to the client-side also.