当前位置:网站首页>You need to know the TCP wave four times
You need to know the TCP wave four times
2022-08-01 01:08:00 【Front-end watermelon brother】
Hello everyone, I'm the front-end watermelon brother.Today I will tell you about the four waves of TCP.
After establishing a TCP connection for a period of time, if you want to disconnect the TCP connection, the process of waving TCP four times will be performed to complete the disconnection operation.
The process of TCP four times is a bit like the three-way handshake that TCP establishes a connection.About the three-way handshake, you can read my article: "TCP three-way handshake you need to know"
The following figure shows the structure of the TCP header. Our TCP four-way wave mainly uses the yellow part.

The initiator of the three-way handshake must be different from the client, and the initiator of the disconnection of the TCP connection can be any party.For the convenience of explanation, below we describe the client as the initiator.
TCP four wave process
Let's look at the schematic first.

The first wave, the client sends a TCP request to the server, and the
in the TCP headerFIN set to 1
seq is set to a random number x
FIN is a flag bit that means finish, 1 is equivalent to true.
seq is a serial number, a place for data, we set it as a random number here to confirm to the server, so as to correspond to this TCP request.
The second wave, the server sends the TCP, and adds the
in the TCP headerACK is set to 1 (acknowledge, meaning "received")
The ack confirmation number is set to x+1 (x is from the first wave)
When the client receives this TCP request, it means that the channel from the client to the server has been closed, and you can no longer send normal data requests to the server.
At this time, the server can still send data to the client.If the server has some previous TCP requests that have not had time to respond, it can still return during the second wave and the third wave.
The third wave, the server sends a TCP request to the client:
FIN set to 1
seq is set to a random number y
Similar to the first wave, only this time the sender is the server.
The fourth wave, the client sends a TCP request to the server:
ACK set to 1
ack confirmation number set to y+1
After the server receives this request, the server can successfully change to the CLOSE state.The client will wait for a period of time before entering the closed state, because the fourth wave may not be successfully sent to the server, so wait and see if the server will resend the first wave because it did not receive the fourth wave.Three waves.
End
Different from the TCP three-way handshake.There are four full waves of TCP to close the connection.This is because between the second wave and the third wave, there may be some slow-processing data that the server needs to send to return, so the two waves are not combined.
I am the front-end watermelon brother, welcome to follow me and master more front-end knowledge.
边栏推荐
猜你喜欢
随机推荐
Matlab / Arcgis处理nc数据
cmake入门学习笔记
设计消息队列存储消息数据的MySQL表格
如何编辑epub电子书的目录
What practical projects can machine learning beginners learn?
JS时间戳的意义是什么?知道sql会考虑加时间戳,JS的时间戳用于什么场景?
MYSQL经典面试题
TCP协议详解
RTL8762DK Lighting/LED (3)
RTL8762DK RTC(五)
MYSQL二阶段提交
Team of Professor Chen Jianyu of Tsinghua University | Contact Safety Reinforcement Learning Framework Based on Contact-rich Robot Operation
WeChat applet page syntax
Carefully summarize thirteen suggestions to help you create more suitable MySQL indexes
Google engineer fired for claiming AI awareness: breach of nondisclosure agreement
Introduction to the five data types of Redis
WAASAP WebClient UI页面标签的决定逻辑介绍
LeetCode每日一练 —— 环形链表问题(面试四连问)
qlib量化源码分析:qlib/qlib/contrib/model/gbdt.py
【 】 today in history: on July 31, "brains in vats" the birth of the participant;The father of wi-fi was born;USB 3.1 standard



![leetcode: 1648. Color ball with decreasing sales value [Boundary find by two points]](/img/b9/7bd33bd981ace25e3bbfc7be9117ff.png)





