当前位置:网站首页>Why is TCP a triple handshake
Why is TCP a triple handshake
2022-07-24 08:56:00 【Xiao Liu xuezhuo】
Reference resources
TCP Why three handshakes , Not twice or four times ?
1. tcp Three handshake process

image.png
It can be seen from the picture that ,tcp The key to three handshakes is , Serial number seq Exchange confirmation of .
2. Why not two handshakes
Because for clients and servers , Both parties to each other Serial number The confirmation of is the key to reliable transmission . The process of two handshakes is as follows :
- A Send a sync signal SYN + A's Initial sequence number
- B Send a sync signal SYN + B's Initial sequence number + B's ACK sequence number
When the second step is completed , We can Guarantee B Known A The serial number of , Because the second step is only executed after the first step is successful . but There is no guarantee A know B The serial number of , Because the transmission in the second step may fail .

The two handshakes are omitted in the figure , Sent SYN=1 The details of the
After two handshakes , Because we assumed ,tcp Only two handshakes , Then when the second handshake is completed ,B You have to think that the connection has been established , No matter whether the transmission of the second handshake is successful . that , If the transmission of the second handshake fails ,A You won't receive it B The serial number of , You can't be sure B The data transmission of starts from . At this time ,B towards A Sent some data (TCP It's full duplex communication , So the server B You can take the initiative to the client A Send a message ), The serial number is attached 20000, By A received :

here A There are two embarrassing choices :
- A Can keep packets . however A even B I don't know the starting serial number of , When will this data package be saved , To reply ACK Well ?
- A Can reply to ACK.ACK Means that the byte data before its serial number has been received , But A even B I don't know the starting serial number of : The starting serial number may be 100, It can also be 1000,A It is impossible to determine which bytes of sequence number are missing , Also dare not reply ACK 了 .
therefore , No matter which choice , It's all inappropriate . This is precisely because A No confirmation B The serial number of . And in the tcp in , By three handshakes , And packet loss processing mechanism ,A and B Will make sure that their serial number is received by the other party .
3. tcp Handling of packet loss in three handshakes
Copy from TCP Why three handshakes , Not twice or four times ? tcp In addition to using three handshakes , We should also deal with packet loss accidents properly , In order to make sure A、B Transmission and confirmation of serial numbers of both parties .
- If the first bag , namely A issue B Of SYN Lost on the way , Didn't arrive B A Will periodically timeout retransmission , Until receipt B The confirmation of
- If the second package , namely B issue A Of SYN +ACK Lost on the way , Didn't arrive A B Will periodically timeout retransmission , Until receipt A The confirmation of
- If the third bag , namely A issue B Of ACK Lost on the way , Didn't arrive B A End of hair ACK, Think unilaterally of TCP by Established state , and B It is obvious that TCP by Active state : a. Suppose that there is no data to send from either side ,B Will periodically timeout retransmission , Until receipt A The confirmation of , When received B Of TCP Connect Also for the Established state , Two way contract can be contracted . b. Suppose this time A There's data to send ,B received A Of Data + ACK, Naturally, it will switch to established state , And accept A Of Data( Hair ACK At the same time, by the way Data close ). c. Assume B There's data to send , The data can't be sent , It will be retransmitted periodically SYN + ACK, Until receipt A To send the data ( received A The confirmation of , The connection has not been established , You can't transmit data ).
such ,tcp Three handshakes of , Plus the processing mechanism of packet loss , To ensure that A、B Confirmation of serial numbers of both parties . This establishes the basis for reliable transmission .
4. Why not four handshakes
Combine the second and third steps of the four handshakes , Three handshakes . In order to improve efficiency , Yes, you can merge 2、3 Step by step .
边栏推荐
猜你喜欢

C language practice questions + Answers:

Wargames NATAS (11-15) problem solving essay

Source code analysis of BlockingQueue (arraybq and linkedbq)

利用opencv 做一个简单的人脸识别

超全总结:Go语言如何操作文件

How to use redis' publish subscribe (MQ) in.Netcore 3.1 project

First acquaintance with JVM

如何将CAD文件导入图新地球中,与影像地形倾斜模型准确叠加

Using OpenCV to do a simple face recognition
![[FFH] websocket practice of real-time chat room](/img/9a/ffd31fe8783804d40edeca515cc96c.png)
[FFH] websocket practice of real-time chat room
随机推荐
What is tiktok creator fund and how to withdraw it?
Treap
基于FPGA的VGA字符显示
Unity C tool class arrayhelper
Beandefinition three ways to load beans
RPC调用方如何实现异步调用:CompletableFuture
在npm上发布自己的库
Using OpenCV to do a simple face recognition
【一起上水硕系列】Final RAD-new literacies
Local warehouse associated with remote warehouse
3587. Connected graph (Jilin University postgraduate entrance examination machine test question)
JUC powerful auxiliary class
Some mistakes that Xiaobai often makes (update from time to time, and promise not to make them again next time)
JQ native write bullet frame mask layer
Optimization of MySQL paging query
Sed add content after a line
How do tiktok merchants bind the accounts of talents?
Clear up some disk space and try again
Tiktok video traffic golden release time
Three tips for finding the latest trends on tiktok