TCP three-way handshake, four waves

TCP is a host-to-host layer transmission control protocol that provides reliable connection services (UDP unreliable connections)

The bit code is the tcp flag bit, and there are 6 kinds of representations:

SYN (synchronous connection establishment)

ACK (acknowledgement means response, confirmation)

PSH (push means that there is DATA data transmission)

FIN (finish closes the connection)

RST (reset means connection reset)

URG (urgent urgent pointer field value is valid)

Three-way handshake:

The first handshake: the client sends a syn packet (syn=x) to the server, and enters the SYN_SEND state, waiting for the server to confirm;

The second handshake: The server receives the syn packet and must confirm the client's SYN (ack=x+1), and at the same time sends a SYN packet (syn=y), that is, the SYN+ACK packet, at this time the server enters the SYN_RECV state;

The third handshake: The client receives the SYN+ACK packet from the server, and sends an acknowledgment packet ACK (ack=y+1) to the server. After the packet is sent, the client and the server enter the ESTABLISHED state and complete the three-way handshake.
The packet transmitted during the handshake process does not contain data. After the three-way handshake is completed, the client and the server officially begin to transmit data. Ideally, once a TCP connection is established, the TCP connection will be maintained until either party actively closes the connection.
Confirmation number: its value is equal to the sender's sending sequence number + 1 (that is, the next sequence number that the receiver expects to receive).

Four waves:

Similar to the "three-way handshake" for establishing a connection, it requires "four waves" to disconnect a TCP connection.

The first wave: the active closing party sends a FIN to close the data transfer from the active closing party to the passive closing party, that is, the active closing party tells the passive closing party: I will no longer send you data (of course, in the fin The data sent before the packet, if the corresponding ack confirmation message is not received, the active closing party will still resend the data), but the active closing party can still accept the data at this time.

The second wave: After the passive closing party receives the FIN packet, it sends an ACK to the other party, and the confirmation sequence number is the received sequence number + 1 (same as SYN, one FIN occupies one sequence number).
The third wave: The passive closing party sends a FIN to close the data transmission from the passive closing party to the active closing party, that is, to tell the active closing party that my data has been sent, and I will not send you any more data.
The fourth wave: After the active closing party receives the FIN, it sends an ACK to the passive closing party, and the confirmation serial number is the received serial number + 1. So far, four waveds have been completed.

The four waving process of TCP (in short): the active closing direction sends the information that the passive closing party will no longer send you data; the passive closing party confirms the received segment of the active closing party; the passive closing direction The active closing party sends the information that I will not send you data again; the active closing party confirms the confirmation of the passive closing party again.

The whole process of TCP three-way handshake and four-way wave is as follows:

write picture description here

TCP three-way handshake process? Why is the three-way handshake used? Is it okay to use the second handshake?

A: The process of establishing a connection is to use the client-server model, assuming that host A is the client and host B is the server.

(1) The three-way handshake process of TCP: host A sends a connection request to B; host B confirms the received segment of host A; host A confirms the confirmation of host B again.

(2) The three-way handshake is used to prevent the invalid connection request segment from being suddenly transmitted to the host B, resulting in an error. The invalid connection request segment means that the connection request sent by host A has not received the confirmation of host B, so after a period of time, host A re-sends the connection request to host B, and the establishment is successful, and the data transmission is completed in sequence. Consider such a special case, the connection request sent by host A for the first time is not lost, but is delayed to reach host B due to the network node. Host B thinks it is a new connection initiated by host A, so host B agrees to connect, and A confirmation is sent back to host A, but at this time, host A simply ignores it, and host B has been waiting for host A to send data, resulting in a waste of host B's resources.

(3) Two-way handshakes are not acceptable. The reason is the special case of the invalid connection request mentioned above. Therefore, using three-way handshakes is just right. Two times may fail, and four or more times are unnecessary and complicated.

Reprinted from http://blog.csdn.net/yanxiaolx/article/details/52123628

Guess you like

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