[Network knowledge] TCP protocol introduction / three-way handshake, the role of waved four times

insert image description here

The reason front-end developers need to understand the three-way handshake and four-way handshake is that these concepts are basic knowledge of the TCP protocol involved in network communication between the client and server. For the front end, if there are problems such as connection failure and delay when requesting server data on the page, you need to have a certain understanding of the status codes corresponding to the three-way handshake and four-way handshake in the TCP protocol.

⭐1. Initial understanding of TCP protocol

TCP (Transmission Control Protocol) is a connection-oriented transport layer protocol, mainly used in indiscriminate networks in the Internet. It provides full-duplex, reliable, ordered, connection-oriented, and byte-stream-based data transfer services that ensure that data is transferred from one application to another in the correct manner.

The TCP protocol specifically includes the following features:

Connection-oriented: Before TCP transmits data, it must go through the connection establishment stage, that is, the three-way handshake. After the data transfer is complete, four more waves are required to close the connection. This process ensures that each data packet can be found in a reliable way and delivered to its directory.

Full-duplex: The TCP connection supports full-duplex mode, that is, both ends can send and receive data at the same time, without waiting for the other party or sending and receiving alternately.

Based on byte stream: In the TCP protocol, data is divided into multiple IP packets, and different IP packets can reach the destination in any order through different paths. Therefore, the TCP data stream is regarded as an infinitely long byte stream. TCP divides this stream into several segments and is responsible for reassembling these segments into the original data.

Reliability: TCP uses methods such as acknowledgment, retransmission, and timeout mechanisms to ensure data reliability, ensuring that each data packet can reach its destination correctly without duplication.

Orderedness: The TCP protocol can ensure that datagrams are delivered one by one in the order they were sent and reassembled at the destination. This guarantees that the receiver can accurately reconstruct the original message.

Flow control and congestion control: The TCP protocol performs flow control and congestion control according to the delay from the source to the destination of the network and the bandwidth of the connection. By using the sliding window protocol and other methods, the sender is prevented from sending too much data, causing the network to be unable to bear the load and blocking.

To sum up, the TCP protocol is a reliable and general-purpose transmission protocol, which is widely used in the Internet. It can realize stable data transmission in an unstable or high-load network environment, and through the state monitoring and feedback of the transmission process Mechanism and flow control and other protection measures to ensure the reliability of data transmission.

⭐Two, three handshakes and four waves

The three-way handshake and four-way handshake are important concepts in the TCP protocol. The following are detailed explanations and their uses:

Three-way handshake
The three-way handshake refers to the mutual confirmation process between the client and the server when establishing a TCP connection. It specifically includes the following steps:

The first step (Client -> Server): The client requests a connection and sends a SYN packet to the server.
The second step (Server -> Client): After receiving the SYN data packet, the server confirms receipt of the request, sends back an ACK data packet, and returns a SYN+ACK data packet according to its current status.
The third step (Client -> Server): After receiving the SYN+ACK data packet from the server, the client returns an ACK confirmation data packet to notify the server that the connection has been established.
The main purpose of the three-way handshake is to ensure that both parties can establish a reliable TCP connection, verify that the connection is normal and ready to accept and send data, and prevent connection interruption or data loss due to network or other reasons.

Four wave of hand
Four wave of fingers to close the TCP connection, the process of mutual confirmation between the client and the server. It specifically includes the following steps:

Step 1 (Client -> Server): The client initiates a shutdown request and sends a FIN packet to the server.
Step 2 (Server -> Client): After receiving the FIN packet, the server sends an ACK packet to the client to confirm that the close request has been received.
The third step (Server -> Client): If the server has unsent data, it will include its FIN packet in the ACK packet to inform the client that it still needs to wait for the data transmission to complete. Otherwise, the server directly sends a FIN packet to the client, indicating that the server is ready to close the connection.
Step 4 (Client -> Server): After receiving the FIN data packet from the server, the client sends back an ACK data packet to confirm acceptance of the close request and notify the server that it can disconnect.
The main purpose of waving four times is to ensure that the TCP connection can be terminated normally, to prevent the client and server from disconnecting before normal shutdown, resulting in data loss, and to release resources for other connections to use.

Guess you like

Origin blog.csdn.net/m0_61118311/article/details/130230943