当前位置:网站首页>Why does TCP establish three handshakes and four waves

Why does TCP establish three handshakes and four waves

2022-06-13 06:39:00 A-linWeb

What is? TCP?
TCP: Transmission control protocol It's a connection oriented protocol . Before sending and receiving data , Both sides should establish a reliable connection . One TCP The connection must be made three times “ dialogue ” To build it up .

A brief description of the three handshakes
The first handshake was successful Let the server know that the client has the ability to send .
The second handshake succeeded Let the client know that the server has the ability to receive and send . But at this time, the server does not know whether the client has received its own information
The third handshake succeeded The server side knows that the client side receives information , Establishing a connection

Brief description of four waves
First wave The client sends one FIN message , Used to close the transfer of data from the client to the server , At this time, the client is in FIN_WAIT_1 state

Second wave Server side received FIN message , Will send ACK message , And a second wave When the server receives FIN after , Will send ACK message , And add the serial number of the client 1 As ACK The value of the message's serial number , Indicates that a message has been received from the client , At this time, the server side is in CLOSE-WAIT state

Third wave If the server agrees to close the connection , Will send a message to the client FIN message , And specify a serial number , At this time, the server side is in LAST-ACK The state of

Fourth wave When the client receives ACK after , be in FIN-WAIT-2 state . To be received FIN When sending a message ACK Message as reply , And the serial number value of the server side +1 As myself ACK The value of the message's serial number , At this time, the client is in TIME-WAIT state . After waiting for a period of time, you will enter CLOSE state , When the server receives ACK After the message , It will become CLOSE state , At this point, the connection is officially closed .

Why did you establish connection communication three times , It took four times to disconnect ?
Because when the server is terminated FIN After the message , Sent ACK The message is only used for answering , It does not mean that the server side also wants to close the connection immediately .
When only the server sends all the messages , Will send FIN message , Tell the client that the connection can be disconnected .

原网站

版权声明
本文为[A-linWeb]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270552590274.html