当前位置:网站首页>Three handshakes and four waves for the interview summary
Three handshakes and four waves for the interview summary
2022-07-29 05:33:00 【Xiao Hong is working hard】
List of articles
One : Three handshakes
Content :
1. What is three handshakes ?
The first handshake : The client will SYN Set as 1, Generate an initial sequence number randomly seq=x, Send to the server , Get into SYN-SENT state ;
The second handshake : Server received from client server SYN After the message , take SYN Set as 1,ACK Set as 1, Generate an initial sequence number randomly seq=y, At the same time, tell the client that the serial number of the next data transmission is x+1;
The third handshake : Client receives server's SYN-ACK After the message , take SYN and ACK All are set for 1, At this time, the serial number sent is x+1 The data of , At the same time, tell the server the serial number of the next data transmission is y+1.
2. The function of three handshakes ?
① Confirm the receiving capacity of both parties , Whether the sending ability is normal .
② Specify your own initialization serial number , Prepare for reliable transmission later .
3. The function of the third handshake (TCP Can I make a connection by shaking hands twice ? Why? ?):
Prevent the invalid connection request message segment from being sent to the server .
The first connection request message segment sent by the client is not lost , But stay at a network node for a long time , As a result, it will not arrive at the server until some time after the connection is released . Originally, this is a message segment that has already failed . But after the server receives the invalid connection request message segment , Mistakenly thought that it was a new connection request sent by the client again , Then send the confirmation message segment to the client , Agree to establish a connection .
If there's no third handshake , So as long as the server confirms , A new connection will be established , But the client did not actually send a request to establish a connection , Therefore, the server will always wait for the client to transmit data , The resources of the server will be wasted .
4. If a connection has been established , But what if the client suddenly fails ?
TCP There is a live timer in , Every time the server receives a request from the client, it will reset the timer , The time is usually set to 2 Hours , If you haven't received any data from the client in two hours , The server will send a detection segment , After every 75 Seconds to send , If it happens in a row 10 There is still no response , The server thinks the client has failed , Connection is closed .
Two : Four waves
Content :
1. What is four waves ?
- First wave : The client sends FIN Message to server , At this time, the serial number of the data sent by the client is seq=u, Get into FIN-WAIT-1 state ;
- Second wave : The server receives FIN message , Respond ACK message , Tell the client to receive his request and agree , At this time, the serial number of the data sent by the server is seq=v, And tell the server that the serial number of the next data you want to receive is ack=u+1, Get into CLOSE-WAIT state ;
- Third wave : Wait until the server data transmission is completed , Send to the client FIN-ACK Request close connection , At this time, the data serial number sent by the server is seq=w(w Is not necessarily v+1,w It refers to the sequence number of the last byte after the end of data transmission +1), And tell the client that the serial number of the next data you want to receive is ack=u+1, Get into TAST-ACK state ;
- Fourth wave : The client receives the request from the server , send out ACK Message to server , Agree to the shutdown request of the server , At this time, the serial number of the data sent by the client is u+1.ack=w+1. Get into TIME-WAIT Stage .
2. Why? TIME_WAIT Status needs to pass 2MSL( Maximum segment lifetime ) To return to CLOSE state ?
①MLS yes “ Maximum message lifetime ”. When waving the server for the third time FIN-ACK After package , The client needs to respond , issue ACK The package agrees to the shutdown request of the server , If you wave your hand for the fourth time in this process ACK The bag is missing , The server will resend the third wave after the timeout FIN-ACK package , So at this time, the client needs to wait for the server to retransmit , And this waiting is not indefinite , But wait 2MLS after , The client did not receive the server's third wave of retransmission packets , Then the client determines the fourth wave ACK The packet was successfully received ,TCP End of connection .
② Prevent the invalid connection request message segment from appearing in the new connection .
stay TIME-WAIT In the state of , Ports on both ends cannot be used , Wait until the 2ML You can continue to use it after the end of time , When the connection is in 2MLS In the waiting phase , Any late segment will be discarded .
边栏推荐
猜你喜欢
【C语言系列】—深度解剖数据在内存中的存储(一) 暑假开篇
Day 3
【剑指offer】— 详解库函数atoi以及模拟实现atoi函数
B - identify floating point constant problems
Vs code的安装步骤及环境配置
Day 2
C语言 一级指针
On Paradigm
Live broadcast preview | how to save 30% labor cost and shorten 80% trademark processing cycle?
Alibaba cloud architect details nine trends in the game industry
随机推荐
【C语言系列】—三种方法模拟实现strlen库函数的方法
365 day challenge leetcode 1000 questions - day 039 full binary tree inserter + find peak II + snapshot array
Summary of the first week
一维数组练习
抽象类与接口
QT learning: qdropevent drag event
Why is Google's internal tools not suitable for you?
刷题狂魔—LeetCode之剑指offer58 - II. 左旋转字符串 详解
Topological ordering of a graph of water
510000 prize pool invites you to fight! The second Alibaba cloud ECS cloudbuild developer competition is coming
PyQt5:第一章第1节:使用Qt组件创建一个用户界面-介绍
【活动预告】云上数字工厂与中小企业数字化转型创新论坛
Allocate memory: malloc() and free()
Day 2
With cloud simulation platform, Shichuang technology supports the upgrading of "China smart manufacturing"
分配内存:malloc()和free()
副作用和序列点
paddle.fluild常量计算报错‘NoneType‘ object has no attribute ‘get_fetch_list‘
NVIDIA Zhou Xijian: the last mile from design to digital marketing
Complete ecological map of R & D Efficiency & selection of Devops tools