Status transition between the TCP server and the client
Understanding status transition is the basis for using the netstat command to diagnose network problems. It is also the key to understanding the process of calling the connect, accept, and close functions.
The following is a connection process in TCP: the client initiates a connection request --> establishes a connection --> interacts with information --> the client initiates a request to close the connection --> closes the connection.
(1) Client TCP status Sequence
(2) TCP status sequence of the server
Client time_wait status
It is worth noting that, in the client TCP status transition diagram, the customer has a time_wait status. Why do we still need such a status when closing the connection?
First, let's look at the following figure:
If the last Ack is lost in the network, the server that fails to receive the confirmation signal resends the last fin, which requires the client to maintain a status information to allow it to resend the final ack. If such status information is not maintained, it will respond with RST (another type of TCP segment), and the server will resolve this RST to receive errors.
However, if TCP needs to complete the necessary work to completely terminate the two-direction data stream of a connection (full-duplex shutdown ), the loss of any of the four sub-sections in the closed connection must be handled correctly. This is one of the important reasons for the time_wait status to exist.