当前位置:网站首页>TCP state transition diagram
TCP state transition diagram
2022-07-04 05:04:00 【StudyWinter】
Pictured

1 Initiate connection initiatively
1.1 theory
The status change of the active connection request is shown in the following figure .
At the very beginning , Both the active requesting end and the passive end are in CLOSED state .
The first stage : When the active requester sends SYN After the sign , Its status changes to SYN_SEND;
The second stage : At this time, the passive party receives the request of the active party , Will send to the active party SYN Flag bit and de confirmation information ACK, After the active party receives the information , Send to the passive party
ACK Confirmation information , At this time, the state of the active party changes to ESTABLISHED, complete TCP Three handshakes connected .
SYN_SEND Generally, it is not easy to see
State change :
CLOSE -- send out SYN -- SEND_SYN -- receive ACK、SYN -- SEND_SYN -- send out ACK -- ESTABLISHED( Data communication state )

1.2 test
Use the command to view the status
View clients
netstat -apn | grep client
Check the server
netstat -apn | grep server
Here is multi process communication , One server In a listening state , the other one server be in ESTABLISHED state
View port number
netstat -apn | grep 9527
2 Active close connection
2.1 theory
The status change of the active close connection request is shown in the following figure .

Before initiating the shutdown request , Both sides are in ESTABLISHED state .
The first stage : The active party initiates a connection closing request , send out FIN, At this time, its state changes to FIN_WAIT_1, When it receives from the passive party ACK After confirmation , Its status changes to FIN_WAIT_2, This is the semi closed state .
The second stage : The active party receives the connection closing request from the passive party (FIN), It sends ACK confirm , The state changes to TIME_WAIT.
The third stage : To really enter CLOSED state , Need to wait 2MSL Duration , Different systems have different time .
State change :
ESTABLISHED( Data communication state ) -- send out FIN -- FIN_WAIT_1 -- receive ACK -- FIN_WAIT_2( Half closed )-- Receiving end to end sending FIN -- FIN_WAIT_2( Half closed )-- Postback ACK -- TIME_WAIT( Only actively close the connection party , Will experience this state ) -- etc. 2MSL Duration -- CLOSE
2.2 test
Use the command to view the status
Check the status of the active shutdown party
netstat -apn | grep 9527
Check the... Of the client TIME_WAIT

Close the client first , Shut down the server again , At this time, the client is in TIME_WAIT state , And there is no problem starting the program again .

Shut down the server first , Close the client again , At both ends TIME_WAIT state , And at this time, the server has 2MSL Duration , Port multiplexing , Can't start .

3 The passive party accepts the connection
3.1 theory
The status change of passive connection request is shown in the following figure

The first stage : Passively accepting connections is generally a server , So from the beginning, I was in LISTEN Listening state , When it receives from the active party SYN After the sign , Then send it to the active party SYN Flags and ACK After confirming the information , Its status changes to SYN_RCVD.
The second stage : When the passive party receives the message sent by the active party ACK After confirming the information , Its status changes to ESTABLISHED.
State change :
CLOSE -- LISTEN -- receive SYN -- LISTEN -- send out ACK、SYN( Send successfully ) -- SYN_RCVD -- receive ACK -- ESTABLISHED( Data communication state )
If the passive party does not receive the active party ACK Confirmation information , The passive party always sends SYN and ACK.

4 Passive close connection
4.1 theory
The status change of the passive close connection request is shown in the following figure .

The first stage : Both the active and passive parties are in the stage of data communication , When the passive party receives the message sent by the active party FIN End mark , And the passive sends ACK After confirming the information ,
The state of the passive party changes to CLOSE_WAIT, It corresponds to the semi closed state of the active party .
The second stage : Send... In the passive direction to the active party FIN After the end flag , Its status changes to LAST_ACK.
The third stage : When the passive party receives the ACK After the confirmation , Its status changes to CLOSE.
State change :
STABLISHED( Data communication state ) -- receive FIN -- ESTABLISHED( Data communication state ) -- send out ACK
-- CLOSE_WAIT ( Explain the opposite end 【 Actively close the connection end 】 It's half closed ) -- send out FIN -- LAST_ACK -- receive ACK -- CLOSE
2MSAL Guarantee the last one ACK Can be successfully received by the opposite end .( Waiting period , The opposite end didn't receive my message ACK, The opposite end will send again FIN request .)
It must appear in 【 Actively close the connection requester 】. --- Corresponding TIME_WAIT state .
5 A term is used to explain
CLOSED: Represents the initial state .
LISTEN: This status indicates a status on the server side SOCKET In a listening state , Can accept connections .
SYN_SEN: This state is related to SYN_RCVD Echo each other at a distance , When the client SOCKET perform CONNECT When the connection , It first sends SYN message , Then we went to SYN_SENT state , And wait for the third handshake sent by the server 2 A message .SYN_SENT Status indicates that the client has sent SYN message .
SYN_RCVD: This status indicates that SYN message , Under normal circumstances , This state is on the server side SOCKET In establishment TCP An intermediate state in a three-way handshake session when connecting , It's short . In this state , When received from client ACK After the message , Will enter the ESTABLISHED state .
ESTABLISHED: Indicates that the connection has been established .
FIN_WAIT_1: FIN_WAIT_1 and FIN_WAIT_2 The real meaning of state is waiting for each other FIN message . The difference is that :FIN_WAIT_1 The state is when socket stay ESTABLISHED In the state of , Want to take the initiative to close the connection , Sent... To the other party FIN message , At this point the socket Enter into FIN_WAIT_1 state .FIN_WAIT_2 The status is when the other person responds ACK after , The socket Enter into FIN_WAIT_2 state , Under normal circumstances , The other party should respond immediately ACK message , therefore FIN_WAIT_1 The state is generally difficult to see , and FIN_WAIT_2 Status available netstat notice .
FIN_WAIT_2: The party that actively closes the link , issue FIN received ACK Enter this state later . It is called a half connected or half closed state . In this state socket Only data can be received , No hair .
TIME_WAIT: It means that I have received FIN message , And sent out ACK message , etc. 2MSL And then you can go back to CLOSED Available status . If FIN_WAIT_1 State, , Receive the other party and bring FIN Logo and ACK When the message is marked , You can go directly to TIME_WAIT state , Without going through FIN_WAIT_2 state .
CLOSING: This state is special , It belongs to a rare state . Under normal circumstances , When you send FIN After the message , It should be received first ( Or received at the same time ) The other person's ACK message , I'll get it back FIN message . however CLOSING Status means you send FIN After the message , Didn't receive the other party's ACK message , But also received the other side's FIN message . When will this happen ? If both sides are almost at the same time close One SOCKET Words , So there's a simultaneous delivery FIN Message situation , That is to say, there will be CLOSING state , That both sides are closing down SOCKET Connect .
CLOSE_WAIT: This status indicates waiting for shutdown . When the other party closes a SOCKET Post send FIN Message to yourself , The system will respond to a ACK Message to the other party , At this point, you will enter CLOSE_WAIT state . The next? , See if any data is sent to the other party , If not, you can close This SOCKET, send out FIN Message to the other party , Close connection . So in CLOSE_WAIT State, , You need to close the connection .
LAST_ACK: This state is passively closed when one party is sending FIN After the message , Finally, wait for each other's ACK message . When I received ACK After the message , That is, you can enter CLOSED Available status .
边栏推荐
- Annex 4: scoring criteria of the attacker docx
- 我们认为消费互联网发展到最后,依然会局限于互联网行业本身
- 加密和解密
- Useful plug-ins for vscode
- 2022年6月总结
- 【MATLAB】MATLAB 仿真模拟调制系统 — SSB 系统
- 附件二:攻防演练保密协议.docx
- The paddlehub face recognition scheme is deployed, and the trained model is deployed and applied in pytchrom
- Notes on the paper "cross view transformers for real time map view semantic segmentation"
- [matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (class I part response waveform)
猜你喜欢

海力士EMMC5.0及5.1系列对比详解

KMP匹配字符串

C basic (VII) document operation

Utiliser des unités de mesure dans votre code pour une vie meilleure

Automated testing selenium foundation -- webdriverapi

STM32F1与STM32CubeIDE编程实例-74HC595驱动4位7段数码管

附件五:攻击过程简报.docx

Test cs4344 stereo DA converter

测试 CS4344 立体声DA转换器

Detailed comparison of Hynix emmc5.0 and 5.1 series
随机推荐
由于使用flash存放参数时,擦除掉了flash的代码区导致进入硬件错误中断
CRS-4013: This command is not supported in a single-node configuration.
Exercise bubble sort
附件三:防守方评分标准.docx
Secondary vocational group network security - memory Forensics
C basic (VII) document operation
附件2-2保密承诺书.docx
力扣 第 300 场周赛
练习-冒泡排序
Utiliser des unités de mesure dans votre code pour une vie meilleure
Developing mqtt access program under QT
拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
Create ASM disk through DD
When using flash to store parameters, the code area of flash is erased, which leads to the interrupt of entering hardware error
《Cross-view Transformers for real-time Map-view Semantic Segmentation》论文笔记
Definition of DCDC power supply current
appliedzkp的zkevm(12)State Proof
Can closed data be deleted by DBCA? can
Zhongke Panyun - module a infrastructure setting and safety reinforcement scoring standard
附件二:攻防演练保密协议.docx