Open In App

TCP Connection Termination

Last Updated : 12 May, 2022
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

In TCP 3-way Handshake Process we studied that how connections are established between client and server in Transmission Control Protocol (TCP) using SYN bit segments. In this article, we will study how TCP close connection between Client and Server. Here we will also need to send bit segments to a server which FIN bit is set to 1. 

TCP supports two types of connection releases like most connection-oriented transport protocols: 
 

  1. Graceful connection release – 
    In the Graceful connection release, the connection is open until both parties have closed their sides of the connection. 
  2. Abrupt connection release – 
    In an Abrupt connection release, either one TCP entity is forced to close the connection or one user closes both directions of data transfer.  

Abrupt connection release : 
An abrupt connection release is carried out when an RST segment is sent. An RST segment can be sent for the below reasons: 

  1. When a non-SYN segment was received for a non-existing TCP connection. 
     
  2. In an open connection, some TCP implementations send an RST segment when a segment with an invalid header is received. This will prevent attacks by closing the corresponding connection. 
     
  3. When some implementations need to close an existing TCP connection, they send an RST segment. They will close an existing TCP connection for the following reasons: 
    • Lack of resources to support the connection 
       
    • The remote host is now unreachable and has stopped responding. 
       

When a TCP entity sends an RST segment, it should contain 00 if it does not belong to any existing connection else it should contain the current value of the sequence number for the connection and the acknowledgment number should be set to the next expected in- sequence number on this connection. 

Graceful Connection Release : 
The common way of terminating a TCP connection is by using the TCP header’s FIN flag. This mechanism allows each host to release its own side of the connection individually. 

 

11

How mechanism works In TCP : 
 

  1. Step 1 (FIN From Client) – 
    Suppose that the client application decides it wants to close the connection. (Note that the server could also choose to close the connection). This causes the client to send a TCP segment with the FIN bit set to 1 to the server and to enter the FIN_WAIT_1 state. While in the FIN_WAIT_1 state, the client waits for a TCP segment from the server with an acknowledgment (ACK).
  2. Step 2 (ACK From Server) – 
    When the Server received the FIN bit segment from Sender (Client), Server Immediately sends acknowledgement (ACK) segment to the Sender (Client).
  3. Step 3 (Client waiting) – 
    While in the FIN_WAIT_1 state, the client waits for a TCP segment from the server with an acknowledgment. When it receives this segment, the client enters the FIN_WAIT_2 state. While in the FIN_WAIT_2 state, the client waits for another segment from the server with the FIN bit set to 1.
  4. Step 4 (FIN from Server) – 
    The server sends the FIN bit segment to the Sender(Client) after some time when the Server sends the ACK segment (because of some closing process in the Server).
  5. Step 5 (ACK from Client) – 
    When the Client receives the FIN bit segment from the Server, the client acknowledges the server’s segment and enters the TIME_WAIT state. The TIME_WAIT state lets the client resend the final acknowledgment in case the ACK is lost. The time spent by clients in the TIME_WAIT state depends on their implementation, but their typical values are 30 seconds, 1 minute, and 2 minutes. After the wait, the connection formally closes and all resources on the client-side (including port numbers and buffer data) are released.

In the below Figures illustrate the series of states visited by the server-side and also the Client-side, assuming the client begins connection tear-down. In these two state-transition figures, we have only shown how a TCP connection is normally established and shut down. 

TCP states visited by ClientSide – 
 

TCP states visited by ServerSide – 
 

Here we have not described what happens in certain scenarios like when both sides of a connection want to initiate or shut down at the same time. If you are interested in learning more about this and other advanced issues concerning TCP, you are encouraged to see Stevens’comprehensive book. 

GATE Question – 
Consider a TCP client and a TCP server running on two different machines. After completing the data transfer, the TCP client calls close to terminate the connection and a FIN segment is sent to the TCP server. Server-side TCP responds by sending an ACK which is received by the client-side TCP. As per the TCP connection state diagram(RFC 793), in which state does the client-side TCP connection wait for the FIN from the server-side TCP? 
(A) LAST-ACK 
(B) TIME-WAIT 
(C) FIN-WAIT-1 
(D) FIN-WAIT-2 

Explanation : (D) 
GATE CS 2017 (Set 1), Question 12 

References – 
TCP Connection Termination – Wikipedia 
http://www.bau.edu.jo/UserPortal/UserProfile/PostsAttach/10617_1870_1.pdf 

 

 


Previous Article
Next Article

Similar Reads

Why TCP Connect Termination Need 4-Way-Handshake?
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 c
8 min read
TCP with explicit link failure notification (TCP-ELFN)
TCP with Explicit Link Failure Notification (TCP-ELFN) is an end to end approach used in TCP Ad Hoc wireless networks to improve the performance by decoupling the path break information from congestion information. TCP-ELFN does not depend upon any routing protocols as it requires explicitly only the link failure notification when there is a path f
2 min read
TCP Tahoe and TCP Reno
TCP is known as a connection-oriented protocol, which ensures reliability and is also responsible for congestion control mechanisms in the network. TCP Tahoe and TCP Reno are two techniques of TCP congestion control, these are used when the sender receives three duplicate acknowledgments. TCP Tahoe where Tahoe is a lake in the USA. This particular
4 min read
TCP Fast Open and TCP/IP Acceleration
The TCP Fast Open (TFO) and TCP/IP Acceleration are techniques used to improve the performance and efficiency of TCP connections in computer networks. These techniques aim to reduce the latency and improve the throughput of the TCP connections, especially for short-lived connections and web browsing scenarios. TCP Fast Open (TFO): The TCP Fast Open
3 min read
TCP Connection Establishment
Prerequisite – TCP 3-Way Handshake Process TCP is a connection-oriented protocol and every connection-oriented protocol needs to establish a connection in order to reserve resources at both the communicating ends. Connection Establishment - 1. Sender starts the process with the following: Sequence number (Seq=521): contains the random initial seque
3 min read
Why is TCP Called a Connection Oriented Protocol?
TCP is a standard connection-oriented protocol that works under the following conditions before any transmission takes place between both devices: Establish a logical connection with the device on receiver's end The Transmission Control Protocol (TCP) is a protocol of the transport layer, which is the "Heart of OSI". And it's a connection-oriented
4 min read
Difference between Connection-oriented and Connection-less Services
Both Connection-oriented service and Connection-less service are used for the connection establishment between two or more devices. These types of services are offered by the network layer.  Connection-oriented service is related to the telephone system. It includes connection establishment and connection termination. In a connection-oriented servi
2 min read
Reasons for Processes Termination
A process in an operating system can be terminated when certain errors or default conditions occur. Following are some of the reasons that lead to process termination, Reasons for Process Termination: Normal Completion: A process can complete its execution in a normal manner by executing an operating system service call. Unavailability of the Requi
3 min read
How Does Termination of Network Cables Affect Connectivity and Performance?
Answer: Termination of network cables is a highly critical process that affects both connectivity and performance to a large extent. When they are properly terminated, these cables allow for reliable and fast data transmission unlike when they are not done properly.Issues related to TerminationConnectivity Issues: Improper termination can lead to p
2 min read
Basic concept of TCP-Vegas
TCP Reno and TCP Tahoe models can determine the congestion in the network only when there some packet loss occurred in the system. So in these models, we have compensated for the packet to sense the congestion in the network. In these models when packet loss occurs the window size is decreased and the system enters the congestion avoidance phase. W
3 min read
Article Tags :
three90RightbarBannerImg