TCP three-way handshake and four-way handshake
TCP three-way handshake and four-way handshake
Three-way handshake
1. First handshake
The client sends a TCP packet whose SYN (Synchronize) flag is set to 1 to the server.
Seq (Sequence Number) is a random Number generated by the operating system. Then, the client enters the SYN_SEND status and waits for confirmation from the server.
2. Second handshake
When the server receives the SYN packet from the client, it sends a confirmation packet (SYN/ACK) to the server.
ACK (Acknowledgment Number) is x + 1 (Sequence Number + 1). The server sends the SYN + ACK packet segment to the client, and the server enters the SYN_RECV status.
3. The third handshake
After receiving the SYN/ACK packet, the client sends an ACK packet to notify the server that the connection has been established.
Three-way handshake Demonstration:
Three-way handshake seq ack first 10000 0 second 20000 + 1 = 10000 third 10001 + 1 = 10001
Four Waves
1. For the first time, the client: "No data is provided to you 』;
2. Second time: SERVER: "I have received this message, and I have no data for you 』;
3. Third time: SERVER: "request to close the connection 』;
4. Fourth time: Client: "OK 』;
After receiving the message, the server closes the connection. If the client fails to receive a response, the connection is also closed.