tcp handshake three times and wave four times

TCP three handshake four times waving diagram

1. TCP three-way handshake

tcp handshake three times and wave four times
The first handshake: When the connection is established, the client sends SYN to the server and enters the SYN_SENT state.
The second handshake: After the server receives the request, it sends back the SYN+ACK signaling to the client. At this time, the server enters the
SYN_RECV state; Second handshake: The client receives the SYN+ACK packet and sends a confirmation ACK packet to the server. The client enters the ESTABLISHED state. After the server receives the request, it also enters the ESTABLISHED state and completes the three-way handshake. At this time, the TCP connection is successful, and the client and the server begin transmit data

1.1 TCP three connection status

tcp handshake three times and wave four times
1. The client initiates a connection
2. The server confirms
3. The client responds again to confirm that the TCP three-way handshake is successful

1. Q: Is the second confirmation not enough?
 Answer: In order to confirm whether the client has received the information sent by the server, if the information sent by the server does not receive a valid reply, the server will send the reconnection information again after the time expires, until it is discarded after the timeout. The server does not receive the final ACK confirmation message from the client, it will remain in the SYN_RECV state, add the client IP to the waiting list, and resend the SYN+ACK message in the second step. The retransmission is generally performed 3-5 times, and the waiting list is polled once every 30 seconds or so to retry all clients. On the other hand, after the server sends a SYN+ACK message, it will pre-allocate resources to store information for the upcoming TCP connection, and this resource will be reserved while waiting for retry. More importantly, the server has limited resources. After the SYN_RECV state that can be maintained exceeds the limit, it will no longer accept new SYN packets, that is, reject the establishment of new TCP connections. DDOS to understand

    比如: A说 中午帮我带个咖啡
                 B说:中午啥咖啡,   然后A一直不回复,长期等待中,再说一次A还是不回复,B就直接会无视说这个逗逼
又或者说  B说:中午啥咖啡
                A回: 你喝啥我就喝啥, 这样就能建立一次有效的连接。

2. Q: Why is the TCP connection establishment a three-way handshake?
The first handshake is successful: it means that the client's data can be received by the server, that the client's sending function is available, and the server's receiving function is available. But the client itself does not know whether the data is received
and the second handshake is successful: it means that the data of the server can be received by the client, the sending function of the server is available, and the receiving function of the client is available. At the same time, the client knows that its data has arrived at the server correctly, and its sending function is normal. However, the server itself does not know whether the data is received
and the third handshake is successful: it means that the server knows that its data has reached the client correctly, and its sending function is normal. So far the service has been successfully established

2. TCP data transmission

The data connection is roughly as shown in the figure
tcp handshake three times and wave four times
. After the client establishes a connection with the server, the client sends data to the server first, and sends it in pieces. After the server receives the data, it will return a confirmation message, indicating that it has been received. To this ack, the server resends an ack message.

tcp handshake three times and wave four times

1. Q: If the client sends data, the client hangs up. Is the file received by the server complete?
   The client sends the data to the server according to MTU (the client will send all the data at one time), the server receives the data in the kernel state, and copies it from the kernel state to the user state. This data is complete, so it is said in the Disconnecting the client after the transmission will not affect the integrity of the data. The only thing to confirm is that the data sent by the client to the server is complete? Here you can use the md5 value to see the test.

3, tcp wave four times

tcp handshake three times and wave four times
1. The first wave: the client sends a [fin+ack] request, indicating that no data is being transmitted, and the status is fin_wait1;
2. The second wave: the server receives the client's request and confirms that it can be interrupted Open the connection and send [ack] to confirm. At this time, the status is close_wait, and the client receives the confirmation information. The status information is changed to fin_wait2.
3. Wave the third time: then it will send a request to disconnect itself [fin, ack], The server is disconnected, and the status bit is last_ack;
4. The fourth wave: the client sends the last confirmation message [ack], the status is time_wait at this time, and the server changes the status to close after receiving it. condition

大白话就是:A: 老大我吃完我走了  
                      B:好的, (A这时准备开走)那你走吧,   
                      A:老大下次再见哈

When the data transmission is completed, there will be four waves of hands, the status is as follows
tcp handshake three times and wave four times

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325152717&siteId=291194637