TCP connection release-four packets waving

table of Contents

 

1. TCP waved four times:

2. Why does the 2MSL time pass without entering the closed state directly?


1. TCP waved four times:

After the transmission is over, both parties of the TCP communication can release the connection, and now the TCP client process in the host A and the TCP server process in the host B are in a connection established state.


Suppose that the application process in host A informs its TCP to release the connection (active close), the TCP client process sends a TCP connection release segment , and enters the termination wait 1 state, the first termination bit of the segment is 1 (FIN=1) , The acknowledgment bit (ACK=1) indicates that this is a TCP connection release message segment, and the value of the sequence number seq is u (it is equal to the sequence number of the last byte of the previously sent message plus one). (TCP stipulates that the segment with FIN set to 1 consumes a sequence number even if it does not carry data), and the value of the confirmation number ack is v (it is equal to the sequence number of the last byte received before the TCP client process plus one) .


After receiving the TCP connection release segment sent by the TCP client, host B sends a TCP confirmation segment and is in a closed waiting state. The ACK in the first part of the message segment is set to 1, indicating that this is a normal ACK confirmation message segment, and the sequence number seq is set to v (the sequence number bit of the last byte that the TCP server process has transmitted before is +1, which is also related to The previous acknowledgment number received by the TCP server matches), and the ack field of the acknowledgment number is set to u+1 (this is the confirmation of the TCP connection release message segment).

At this time, the TCP server process notifies the application process that the TCP client process is about to disconnect from itself, and the connection between the TCP client process and the TCP server process is released. At this time, the TCP connection is half-closed, and the TCP server process has no data to send.


If the TCP server process still has data to send at this time , then the TCP client process will receive the data. At this time, the TCP client is in the termination waiting state 2. If the TCP server process has no data to send, then it sends a TCP connection release message Segment and enter the final confirmation state. The termination bit FIN of the TCP connection release segment is set to 1, and the ACK is set to 1, indicating that this is a TCP connection release segment, and the previously received segment is confirmed. The seq value of the TCP connection release message segment is w (maybe because the TCP server has sent some data), and ack is set to u+1 (the sequence number of the TCP connection release message is confirmed).

 The TCP client process in host A sends a TCP confirmation message segment according to the TCP connection release message segment sent by the TCP server process of host B , and is in a time waiting state. The value of the acknowledgment bit ACK is set to 1, the value of seq is set to u+1 (because the sequence number value of the TCP connection release is u although it does not carry data but a sequence number is consumed), the value of the acknowledgment number is set to w+1, This is a confirmation of the release of the received TCP connection.

 


Host B is in the closed state after receiving the TCP acknowledgment message from host A, and the client process in host A has to pass twice the MSL before entering the closed state. MSL: Longest message segment lifetime.


 2. Why does the 2MSL time pass without entering the closed state directly?

This is because if you enter the closed state directly, and the TCP confirmation segment sent by the TCP client is lost, then the TCP server cannot receive the last TCP confirmation segment, and the TCP server will always retransmit the TCP connection Released but at this time the TCP client is already in the closed state, it will ignore the TCP connection release sent by the TCP server, and the TCP server will continue to send the TCP connection release, eventually causing a waste of resources.

 


Information reference: Lake University of Science and Technology

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_43690348/article/details/112749306