当前位置:网站首页>TCP connection and disconnection, detailed explanation of state transition diagram

TCP connection and disconnection, detailed explanation of state transition diagram

2022-06-26 06:14:00 Ah Jie's small fish pond

One 、 summary

This paper mainly focuses on TCP The three handshakes and four waves in the state transition diagram are summarized , About the process of handshake and wave, you can see the following :
https://blog.csdn.net/hjlogzw/article/details/122312496

Two 、 Explain the state transition diagram in detail

Let's start with a classic state transition diagram :
 Insert picture description here
CLOSED: The initial state .

LISTEN: That is, the server is listening , You can receive customer connections , It's called listen Function is in this state .

SYN_RCVD: It generally indicates the status of the server , I'll take it SYN The message is sent until the client returns the last of the three handshakes ACK message , After receiving the client ACK Then establish the connection , Enter into ESTABLISHED state .

SYN_SENT: It generally indicates the status of the client , And SYN_RCVD Corresponding , When the client calls connect Function time , It will be sent first SYN message , This is when we enter SYN_SENT state , And wait for the server to ACK message .

ESTABLISHED: This status indicates that the connection has been established .

FIN_WAIT_1: When the connection enters ESTABLISHED Post state , If one end wants to actively close the connection , Send to the opposite end FIN message , Now enter FIN_WAIT_1 state , When the opposite end replies ACK After the message , Then go to FIN_WAIT_2 state .

FIN_WAIT_2: The connection in the changed state is in the semi connected state , It means that one party requests to close the connection , But the other party still has data to send , Close the connection later .

TIME_WAIT: When receiving from the other party FIN message , And sent ACK After the message , becomes TIME_WAIT state , Waiting for the 2MSL Then return to the initial state CLOSED. It is worth noting that , If in FIN_WAIT_1 State, , Receive the other party and bring FIN Logo and ACK When the message is marked , You can go straight to TIME_WAIT state , No need to go through FIN_WAIT_2 state , As shown in the figure below .
 Insert picture description here

CLOSING: This state is rare , In general , Sending FIN After the message , Should first receive the other party's ACK message , Again ( Or received at the same time ) The other person's FIN message . But CLOSING Status indicates sending FIN After the message , Didn't receive the other party's ACK message , But also received the other party's FIN message , This actually shows that both sides should close This connection , As shown in the figure below :
 Insert picture description here

CLOSE_WAIT: I.e. wait for shutdown , When the opposite end calls close Post send FIN The message is sent to the local terminal , In response ACK And then we went to CLOSE_WAIT state , Next, you need to consider whether there is any data not sent to the other party , If not, you can send FIN Message to the other party , This closes the connection .

LAST_ACK: That is, the passive closing party is sending FIN After the message , Waiting for each other's ACK Status of the message , When you receive it, you will enter CLOSED The initial state .

notes :
2MSL Why :

  1. Give Way 4 This handshake closure process is more reliable ;4 The last handshake ACK It is sent by the active shutdown party , If this ACK The loss of , The passive closing party will send another FIN To come over . If the active shutdown party can maintain a 2MSL Of TIME_WAIT state , There is a greater chance for the lost ACK Sent again .
  2. Prevent the last response package from affecting the new connection .

Reference resources :
https://blog.csdn.net/qq_32642107/article/details/107289298
https://www.csdn.net/tags/MtTaEg3sMzAxNTI3LWJsb2cO0O0O.html
https://baijiahao.baidu.com/s?id=1707040989071212058&wfr=spider&for=pc
https://wenku.baidu.com/view/d165f05c3b3567ec102d8a2a.html

原网站

版权声明
本文为[Ah Jie's small fish pond]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260603367084.html