当前位置:网站首页>Second handshake?? Three waves??
Second handshake?? Three waves??
2022-07-29 10:14:00 【Walnut is surnamed Hu, and butterfly is also surnamed Hu】
When we learn 《 computer network 》 At the time of this course , I will definitely learn TCP This classic transport layer protocol ,TCP There is a feature called Connection management , This feature leads to two concepts ,TCP Three handshakes and four waves . Why three times , And why is it four times this problem has troubled me for a long time , Today I will explain this reason in detail .
On this question , Most articles will quote 《 computer network 》 A sentence in it .
Prevent invalid connection requests from being sent to the server , So there's a mistake
Actually, that's too broad , Can't really understand .
TCP What is the communication process like ?
Send messages to each other , This is a very easy thing to understand .
Such as this :
At this time, we need to introduce a concept , be called TCP The buffer :
TCP The buffer of can be understood as a very large array :

When there is data transmission in our application layer , Writing data to the transport layer through the system call interface is written in TCP In the buffer of the Protocol ,TCP Meeting malloc Two segments of memory space . The role of having a buffer is obvious :
- Improve the efficiency of the application layer
- Only OS,TCP The protocol can know the network , Even the status details of the other party , So only TCP agreement , Can handle how to send , When to send , How many hair , What to do if something goes wrong , Because the buffer exists , So we can achieve application layer and TCP Decoupling
my TCP There is a lot of data in the buffer , Some data has been sent , Some have not been sent , So where should we develop and send the connection this time ? This is not necessarily from 0 Location ( Subscript ) At the beginning , therefore client End sum server The client needs to know where the buffer of the other party comes from ( The array subscript ) Develop and send data .
- For reliable data transmission , TCP The parties to the agreement , You have to maintain a serial number , To identify the packets sent , What has been received by the other party . The process of three handshakes is that the communication parties inform each other of the starting value of the serial number , And confirm that the other party has received the start value of the serial number
- If it's just two handshakes , At most, only the starting serial number of the connection initiator can be confirmed , The serial number chosen by the other party is not confirmed
So let's see TCP The whole process of communication :

You can see the process of confirming the serial number by both parties .
Why? TCP You need to shake hands ? Can you stop shaking hands ?
If the contrast UDP Agreement can be found ,UDP Handshake is not required in the Protocol , Here we need to draw TCP and UDP The characteristics of the Protocol , A key feature is ,TCP The agreement is a reliable agreement ,UDP An agreement is an unreliable agreement .
Reliable agreement means : The data received by the receiver is complete , Orderly , Error free .
Unreliability means : The data received by the receiver may be partially lost , Sequence is not guaranteed .
TCP Protocol in order to achieve reliability , Both sides of the communication need to know whether the data they send has been received by the receiver , If not received , You need to resend . In order to achieve this requirement , About to lead out Serial number and Confirm the serial number .
The sender is sending a packet ( Assume the size is 10 byte) when , At the same time, send a serial number ( Assuming that 500), After the receiver receives the packet , You can reply with a confirmation number (510 = 500 + 10) Tell sender “ I have received your packet , You can send the next packet , The serial number from 510 Start ” .
In this way, the sender can know which data has been received , What data was not received , Need to resend .
So there is the process of the above figure , This explains why 3 Time , instead of 2 Time .

Someone may be interested in the above picture TCP There are questions about the data of the communication process .
- Why three handshakes, the last handshake , Reply in the diagram above seq = x+1 .
Take a look at a passage in the big black book :
What is said here is very complicated , It's actually : my ACK The serial number inside is the next one I need to get .

So why four waves ?
Can't you wave your hand like three handshakes ?
The answer is no , as a result of :TCP Agreement is Full duplex .client and server Both ends need to transmit and process data . I client End request to close the link , send out FIN, from OS The kernel rules , send out FIN It will echo immediately after ACK To show that I have received this message , But my server The client may be processing data at this time , So you can't close it immediately , You can only send it after the matter is handled FIN to client, It means I'm done ,client Echo after receiving ACK To indicate receipt of , then server close ,client stay 2MSL After that, it is also closed .
If server There is nothing to deal with , that FIN and ACK Will be merged and sent , That is the so-called three waves .
in other words , Compared to three handshakes , Four waves, one more I'll call you back when I finish my work The process of .
It's like I go out to play with walnuts :
I : walnut , Let's go out and play !
walnut : All right ! But I have something , I'll call you after I finish the work .
walnut : I'm done , Let's go !
I : well !
Why? client etc. 2MSL Just close ?
This is also the guarantee of reliability , If I send it ACK I'll wait for the packet to be sent again , What if I quit the second ?
边栏推荐
- After the thunderstorm of two encryption companies: Celsius repayment guarantee collateral, three arrow capital closed and disappeared
- The latest translated official pytorch easy introduction tutorial (pytorch version 1.0)
- [ts]Typescript学习记录坑点合集
- [paper reading] q-bert: Hessian based ultra low precision quantification of Bert
- Follow teacher Tian to learn practical English Grammar (continuous update)
- 这才是开发者神器正确的打开方式
- Talk about multithreaded concurrent programming from a different perspective without heap concept
- After eating Alibaba's core notes of highly concurrent programming, the backhand rose 5K
- Implementation and verification logic of complex expression input component
- MySQL logging system: binlog, redo log and undo log
猜你喜欢

Orbslam2 installation test and summary of various problems

高效能7个习惯学习笔记

函数——(C游记)

Intel joins hands with datawhale to launch learning projects!

How to customize the opportunity closing form in dynamics 365online

Some suggestions for programmers to leave single
![[C language] Sanzi chess (intelligent chess playing + blocking players)](/img/36/4a269887189e64562227a8592433c3.png)
[C language] Sanzi chess (intelligent chess playing + blocking players)

"Focus on machines": Zhu Songchun's team built a two-way value alignment system between people and robots to solve major challenges in the field of human-computer cooperation

Talk about multithreaded concurrent programming from a different perspective without heap concept

英特尔联合Datawhale,发布学习项目!
随机推荐
How to customize the opportunity closing form in dynamics 365online
【论文阅读】I-BERT: Integer-only BERT Quantization
Knowledge points of common interview questions: distributed lock
Follow teacher Li to learn line generation determinant (continuous update)
高效能7个习惯学习笔记
综合设计一个OPPE主页--页面的底部
Are you familiar with the redis cluster principle of high paid programmers & interview questions series 122? How to ensure the high availability of redis (Part 2): cluster mechanism and principle, clu
Selenium series 5-xpath path expression
Soft exam summary
shell编程之sed,正则表达式
这才是开发者神器正确的打开方式
Notes for Resume Writing
跟着武老师学高数——函数、极限和连续(持续更新)
Function - (C travel notes)
Linear regression of machine learning (least square handwriting +sklearn Implementation)
网络图片转换本地图片 - 默认值或快捷键
尹伊:我的学习成长路径
待人宽容大度
[FPGA tutorial case 18] develop low delay open root calculation through ROM
Implementation and verification logic of complex expression input component