当前位置:网站首页>Three handshakes and four waves
Three handshakes and four waves
2022-08-11 09:03:00 【learn record】
目录
重要概念
SYN(同步请求信号)
ACK(响应信号)
ACK=1,响应有效
ACK=0,响应无效
ack(确认信号)
seq(序列号)
三次握手

第一次握手:
客户端向服务端发送SYN=1同步请求信号,序列号seq=x;客户端进入SYN_SEND状态(Sync request status)
第二次握手:
After the server receives the signal from the client,向客户端发送SYN=1信号,ack=x+1,ACK=1响应,seq=y;Server status hasLISTEH转为SYN_SEND
第三次握手:
After the client receives the signal,发送SYN=1,seq=x+1,ack=y+1;客户端进入ESTABLISHED状态(连接状态),The server also enters after receiving the signalESTABLISHED状态.
问题1:为什么要三次握手?
答:The first handshake server knows that the client has the signaling function;第二次握手,The client knows that the server has the ability to receive and send signals;第三次握手,The server-side self-guided client has the ability to receive signals.
问题2:为什么是三次握手,不是两次,四次?
答:Assume two handshakes,The client sends a synchronization request to the serverSYN=1,For special reasons such as signal interruption,The server did not receive the signal,一直在LISTEN状态;The client then thinks that the data was not sent for network reasons,Send the same signal to the server again,Then the server receives the signal to establish a connection,But the network suddenly recovered,Make the first signal sent to the server sent again,After two handshakes,The server waits for the client to confirm,But the client thinks only one request was sent,The information on both sides is not equal,The server has been in a state of waiting for confirmation.The three-way handshake essentially solves the problem of unreliable network channels.
The four-way handshake is a waste of resources,Because of the three-way handshake, both the client and the server can know each other's signal sending and receiving capabilities.
四次挥手

第一次挥手:
客户端向服务端发送FIN信号(结束信号),and send a serial numberseq=m ,客户端从ESTABLISHED状态进入FIN_WAIT1状态(等待结束1状态).
第二次挥手:
服务端收到信号后,向客户端发送响应(ACK=1)、序列号seq=y和确认信号ack=m+1,同时服务端进入CLOSE_WAIT状态(关闭等待状态).
第三次挥手:
客户端在CLOSE_WAIT(等待关闭状态)时,Data can be sent to the client.At the same time, the server sends an end signal to the client(FIN)、响应(ACK)、序列号(seq=n)和确认信号ack=m+1.服务端进入最后确认状态(LAST_ACK);The client enters after receiving the signalFIN_WAIT2(等待结束2状态)
第四次挥手:
After the client receives the signal,Send a response to the server(ACK),序列号(seq=m+1),确认号(ack=n+1),At the same time, it enters the waiting time by itself(TIME_WAIT),Close the connection directly after two seconds;The server closes the connection after receiving the signal(CLOSE).
问题1:为什么客户端需要等待2秒?
答:It is to ensure that the server can receive the confirmation signal.Because it is assumed that the client closes the connection directly after sending the signal,Once the signal is lost during transmission,It will cause the server to wait for the shutdown state.But the client waits two seconds,This is that the server does not receive the signal and the client will send the signal again,The reliability of signal transmission is guaranteed.
边栏推荐
猜你喜欢
随机推荐
持续集成/持续部署(2)Jenkins & SonarQube
通过Xshell连接Vagrant创建的虚拟机
法律顾问成了律所鸡肋产品了吗?
for循环和单击相应函数的执行顺序问题
软件定制开发——企业定制开发app软件的优势
基于C#通过PLCSIM ADV仿真软件实现与西门子1500PLC的S7通信方法演示
轻量级网络(一):MobileNet V1,V2, V3系列
最强大脑(2)
The no-code platform helps Zhongshan Hospital build an "intelligent management system" to realize smart medical care
QTableWidget 使用方法
MATLAB实战Sobel边缘检测(Edge Detection)
Redis的客户端连接的可视化管理工具
万字长文带你了解多态的底层原理,这一篇就够了
安装ES7.x集群
Getting Started with Kotlin Algorithm to Calculate the Number of Daffodils
WordpressCMS主题开发02-制作顶部header.php和footer.php
Audio and video + AI, Zhongguancun Kejin helps a bank explore a new development path | Case study
Kotlin算法入门求回文数算法优化一
第一次因没有找到iframe元素而怀疑selenium4是不是有bug?
opencv 制作趣图




![ASP.NET Core 6框架揭秘实例演示[32]:错误页面的集中呈现方式](/img/c9/93ab353c4908adaaae0da2cc3b6a3c.png)




