TCP Connection Termination | FIN Segment

Spread the love

Three Way Handshake-

 

Before you go through this article, make sure that you have gone through the previous article on Three Way Handshake.

 

We have discussed-

  • TCP uses Three Way Handshake to establish a connection between the sender and receiver.
  • Connection establishment using Three Way Handshake involves the steps as shown-

 

 

Also Read- TCP Retransmission

 

In this article, we will discuss how a TCP connection is terminated.

 

TCP Connection Termination-

 

A TCP connection is terminated using FIN segment where FIN bit is set to 1.

 

Consider-

  • There is a well established TCP connection between the client and server.
  • Client wants to terminate the connection.

 

The following steps are followed in terminating the connection-

 

Step-01:

 

For terminating the connection,

  • Client sends a FIN segment to the server with FIN bit set to 1.
  • Client enters the FIN_WAIT_1 state.
  • Client waits for an acknowledgement from the server.

 

 

Step-02:

 

After receiving the FIN segment,

  • Server frees up its buffers.
  • Server sends an acknowledgement to the client.
  • Server enters the CLOSE_WAIT state.

 

 

Step-03:

 

After receiving the acknowledgement, client enters the FIN_WAIT_2 state.

 

Now,

  • The connection from client to server is terminated i.e. one way connection is closed.
  • Client can not send any data to the server since server has released its buffers.
  • Pure acknowledgements can still be sent from the client to server.
  • The connection from server to client is still open i.e. one way connection is still open.
  • Server can send both data and acknowledgements to the client.

 

 

Step-04:

 

Now, suppose server wants to close the connection with the client.

 

For terminating the connection,

  • Server sends a FIN segment to the client with FIN bit set to 1.
  • Server waits for an acknowledgement from the client.

 

 

NOTE

If server wanted,

It could have sent the FIN segment along with the previous acknowledgment that it sent to the client.

 

Step-05:

 

After receiving the FIN segment,

  • Client frees up its buffers.
  • Client sends an acknowledgement to the server (not mandatory).
  • Client enters the TIME_WAIT state.

 

 

TIME_WAIT State-

 

  • The TIME_WAIT state allows the client to resend the final acknowledgement if it gets lost.
  • The time spent by the client in TIME_WAIT state depends on the implementation.
  • The typical values are 30 seconds, 1 minute and 2 minutes.
  • After the wait, the connection gets formally closed.

 

Next Article- Practice Problems On TCP

 

Get more notes and other study material of Computer Networks.

Watch video lectures by visiting our YouTube channel LearnVidFun.

Summary
TCP Connection Termination | FIN Segment
Article Name
TCP Connection Termination | FIN Segment
Description
TCP Connection Termination- A TCP connection is terminated using FIN segment where FIN bit is set to 1. Three Way Handshake is used to establish a TCP Connection. The steps involved in terminating a TCP Connection are described.
Author
Publisher Name
Gate Vidyalay
Publisher Logo

Spread the love