当前位置:网站首页>Three handshakes and four waves

Three handshakes and four waves

2022-08-11 09:03:00 learn record

目录

重要概念

三次握手

第一次握手:

第二次握手:

第三次握手:

问题1:为什么要三次握手?

问题2:为什么是三次握手,不是两次,四次?

四次挥手

 第一次挥手:

第二次挥手:

第三次挥手:

第四次挥手:

问题1:为什么客户端需要等待2秒?

重要概念

        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.

原网站

版权声明
本文为[learn record]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208110857008813.html