TCP Connection Termination (Networking)

From ben.goodacre.name/tech

Jump to: navigation, search

Normal Connection Termination

Each side closes the connection independently by sending a FIN packet and waiting for an ACK, 4 packets are exchanged.

-------------- FIN --------------> 
<------------- ACK ---------------
<------------- FIN ---------------
-------------- ACK ------------->
Connection status Description
FIN_WAIT1Closer wishing to close a connection and has sent a FIN packet but has not yet received and ACK packet back from the closee.
CLOSE_WAITClosee receives FIN packet and send an ACK packet, it must wait for the app using it to be told the end is closing so the app here can finish properly.
FIN_WAIT2Closer has now received ACK packet back from the client and is now waiting for the closee's FIN.
LAST_ACKThe closee's receives notice that the app has finished and it sends its FIN to the closer and is now waiting for the closer's ACK. It is waiting for the 'last ack'.
TIME_WAITCloser receives the FIN packet and sends back an ACK packet. This is the very last packet sent in the TCP closing process. The closer reserves the port for twice the maximum segment lifetime (by default) to ensure no stray packets are receives by another process that might use the same port afterwards.
CLOSEDClosee receives the ACK packet from the closer.
CLOSEDCloser reservation of the port expires.

Simultaneous Close

Each side closes its connection simultaneously, 4 packets are still exchanged.

-------------- FIN -------------->
<------------- FIN ---------------
-------------- ACK ------------->
<------------- ACK ---------------
Connection Status Description
FIN_WAIT1Closer sends a FIN packet and is waiting for the closee's ACK as normal.
FIN_WAIT1The other machine also wishes to end the connection and sends back a FIN simultaneously. TCP close becomes and active close.
CLOSINGBoth machines receives a FIN packet and sends an ACK packet back to each other. They are in this state until they receive each others respective ACK packet.
TIME_WAITEach machine enters this state once they have received the other machines ACK. The port is reserved for twice the maximum segment lifetime (by default) to ensure no stray packets are receives by another process that might use the same port afterwards.

References

http://www.tcpipguide.com/free/t_TCPConnectionTermination-2.htm
http://ttcplinux.sourceforge.net/documents/one/tcpstate/tcpstate.html

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox