The six control bits of TCP are:
URG: the packet segment is urgent.
Ack: the confirmation number is valid.
Psh: It is recommended that the computer immediately submit the data to the application.Program. RST: Connection reset. Purpose: Close the connection quickly without confirmation. SYN: process synchronization. When the handshake is complete, SYN is 1, indicating that TCP has established a connection. In all subsequent message segments, SYN is set to 0. Fin: data that is no longer to be sent by the source host. If the source host data is sent, the fin position 1 in the header of the last packet segment to be sent under the connection is set to 1, or the position 1 in the header sent after the packet segment.
TCP connection Establishment
A TCP connection is a full-duplex connection, which must be established in two directions. This method requires that all packets be numbered (32-bit). Before establishing a connection, the server first passively opens the ports it is familiar with and listens on the ports, when the client wants to establish a connection with the server, it initiates a request to open the port (usually a temporary port) and then enters the three-way handshake process:
The first handshake: the customer sends a connection request to the server. The synchronization mark SYN at the beginning of this segment is set to 1, and the initial client sequence number seq of this connection is entered in the header, (For example, seq = 26500 ). The client enters the syn_send status and waits for confirmation from the server.
The second handshake: After the server receives a request, it sends back the connection confirmation (SYN + ACK). The synchronous mark SYN in the header of this segment is set to 1, indicating that the connection is accepted, and Ack is set to 1, it indicates the confirmation of the received segments. In combination with Ack, it is the next serial number (ACK 26501) to be received. This section also provides its own initial serial number (for example, SEQ = 29010 ). The confirmation of the Request segment completes a connection. The server enters the syn_recv status.
The third handshake: The validation segment sent by the customer to the server. The ack identifier in the segment header is set to 1, which indicates confirmation of the received segment, the next serial number to be received in combination with Ack is set to the serial number of the received segment plus 1 (ACK 29011). The confirmation of the server initialization serial number completes the connection in another direction. The client and the server enter the established status. After three handshakes are completed, the client and the server start to transmit data.
When the second handshake occurs, the client receives the server ack and the client-server connection has been established. During the third handshake, the server receives the ACK from the client, and the server-client connection is established. The three-way handshake sends the first TCP packet with no data segment. If data is sent during the third handshake, you can add data segments. In the three-way handshake process, not only the connection is established, but also the window proportion negotiation and MSS size negotiation are conducted.
TCP connection Removal
Both sides of the current connection can initiate a removal operation, but a simple removal of the connection may cause data loss. Therefore, TCP uses a four-way handshake to remove the connection.
The four handshakes are similar to the three handshakes:
1. Send a demolition request
② 2. receive the request and confirm it concurrently. 1. After receiving the confirmation, no data will be sent, but any data will be received (semi-join)
③ 2 release demolition request
④ 1 received the request and confirmed that the removal was completed.
Why isn't a second handshake and a third handshake joined together during the disconnection process, just like a connection project? This is because when the client removes the connection, it can also receive data, and the server may also send data to the client. This is a difference between connection establishment and removal.