Summary of TCP state changes

The development and maintenance process is always inseparable from the network, and the network is almost always inseparable from the knowledge of TCP.

After the usual practice and reading the harvest.

Here is a summary of the meaning of each state of the TCP protocol.

ps: You can see the current state of TCP through the netstat command.

1. A TCP state transition diagram on the Internet is as follows, which describes all possible state changes of the TCP state.

Second, it can be divided into server and client to describe the change of TCP state.

3. The server is in the LISTEN state after calling the listen system call. At this time, wait for the arrival of the client's active connection.

4. When the server receives the SYN connection message from the client and replies with the SYN acknowledgment (ACK) message, it becomes the SYN RCVD state. Indicates that the SYN from the client has been received.

5. On the basis of 4, the server enters the ESTABLISHED state after receiving the confirmation message just confirmed. The three-way handshake is now complete.

6. When the server receives the active close connection request sent by the client, that is, it enters the CLOSE_WAIT state after receiving the FIN message, and then enters the LAST_ACK state after sending the FIN message to the client.

==================

7. After the client sends a SYN packet and actively connects to the server, it enters the SYN_SENT state. This state is theoretically not too long. If it is always in the SYN_SENT state, the server does not respond. Please check whether the configured IP and port of the server are correct.

8. On the basis of SYN_SENT, after receiving the SYN sent by the server, and the ACK confirmation occurs, it will enter the ESTABLISHED state. Connection has been established.

9. The client performs active shutdown. After sending the FIN packet, it first enters the FIN_WAIT1 state, and after receiving the SYN confirmation, it progresses to the FIN_WAIT2 state, and continues to receive the FIN packet and enters the TIME_WAIT state.

 

Note: There are two reasons for entering the TIME_WAIT state instead of directly closing: reliable termination of the TCP connection to ensure that late TCP packets have enough time to be recognized and lost.

 

Let's talk about the difference between the two easily confused states.

CLOSE_WAIT : passively close, enter this state after receiving the FIN packet sent by the other party. After replying FIN to the other party, it becomes LAST_ACK state.

TIME_WAIT : Enter this state after actively closing, actively sending FIN packets, and receiving FIN packets from the other party.

 

 

Let's talk about the reset report segment:

Under certain conditions, TCP will send a segment with the RST flag to the other end, which is a reset segment. Used to notify the other party to close the connection or reconnect, discuss three situations:

a. When accessing a port that does not exist

b. Abnormal termination of the connection, TCP provides a method of abnormal termination of a connection, that is, sending a reset segment to the other party. Once the reset segment is sent, all data queued for transmission at the sender is discarded.

c. Handling half-open connections

   The server (client) closes or terminates the connection abnormally, and the other party does not receive the end message (may send a network failure). At this time, the client (server) still maintains the original state, but the server (client) ) There is no information about the connection even after restarting. This state is called a half-open state. At this time, the client (server) writes data to the half-open connection, and the other party will respond with a reset segment.
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326848675&siteId=291194637