当前位置:网站首页>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.
边栏推荐
- Getting Started with Kotlin Algorithm to Calculate the Number of Daffodils
- 软件定制开发——企业定制开发app软件的优势
- 研发了 5 年的时序数据库,到底要解决什么问题?
- MATLAB实战Sobel边缘检测(Edge Detection)
- 谁能解答?从mysql的binlog读取数据到kafka,但是数据类型有Insert,updata,
- Unity3D——自定义类的Inspector面板的修改
- MySql的索引
- Kotlin算法入门计算水仙花数
- 刷题错题录2-向上取整、三角形条件、字符串拼接匹配、三数排序思路
- golang string manipulation
猜你喜欢
随机推荐
Essential C# scripting skills for Unity developers
gRPC系列(一) 什么是RPC?
基于 VIVADO 的 AM 调制解调(3)仿真验证
MySql的索引
gRPC系列(二) 如何用Protobuf组织内容
刷题错题录2-向上取整、三角形条件、字符串拼接匹配、三数排序思路
mysql添加用户以及设置权限
tar 命令使用
Interview questions about Android Service
MySql事务
redis模拟面试
WordpressCMS主题开发01-首页制作
零基础创作专业wordpress网站12-设置标签栏图标(favicon)
前几天,小灰去贵州了
Getting Started with Kotlin Algorithms Calculating Prime Factors
如何通过开源数据库管理工具 DBeaver 连接 TDengine
1.3版本自定义TrainOneStepCell报错
Detailed Explanation of the Level 5 Test Center of the Chinese Institute of Electronics (1)-string type string
mysql数据查询因为查询的时间跨度过大导致cup爆满应该怎么办
Kotlin算法入门求回文数数算法优化二数字生成规则