Interview Question: Explanation of TCP three-way handshake and four waved hands

The purpose of using three-way handshake and four-way handshake:

Three-way handshake: In order to provide reliable transmission, TCP sends the sequence numbers of data packets in a specific order before sending new data, and requires confirmation messages after these packets are transmitted to the target machine.

Wave four times: For an established connection, TCP uses an improved four-way handshake to release the connection (using a segment with a FIN additional mark).

The steps of the three-way handshake:

First time
First handshake: When establishing a connection, the client sends a syn packet (seq=j) to the server, and enters the SYN_SENT state, waiting for the server to confirm; SYN: Synchronize Sequence Numbers.

Second
second handshake: server receives syn packets, must confirm the customer SYN (ack = j + 1) , while themselves sends a SYN packet (seq = k), i.e., SYN + ACK packet, then the server into SYN_RECV status.

The third
third handshake: the client receives the SYN + ACK packet to the server, the server sends an acknowledgment packet ACK (ack = k + 1) , this packet is sent, the client and server into the ESTABLISHED (TCP connection succeeds) state , To complete the three-way handshake.

Insert picture description here


Four waved steps:

In the first step, when the application program of host A informs that TCP data has been sent, TCP sends a message segment with FIN additional mark to host B (FIN stands for English finish).

In the second step, after host B receives the FIN segment, it does not immediately reply to host A with the FIN segment, but first sends an acknowledgment sequence number ACK to host A, and at the same time informs its corresponding application: the other party requested to close Connection (the purpose of sending the ACK first is to prevent the other party from retransmitting the FIN segment during this time).

In the third step, the application program of host B tells TCP: I want to completely close the connection, and TCP sends a FIN segment to host A.

In the fourth step, after host A receives the FIN segment, it sends an ACK to host B to indicate that the connection is completely released.

Insert picture description here

problem

1. Why does the timer set by the client wait for 2MSL (the maximum time of two communication messages) when the connection is disconnected?
2. Why is the three-way handshake used to establish the connection instead of two or four times?

Guess you like

Origin blog.csdn.net/m0_50654102/article/details/113887143