Three TCP handshake with the four waving notes

Three TCP handshake with the four waving notes

TCP Flags

URG: Urgent Pointer flag

ACK: acknowledgment number flag

PSH: push flag

RST: Reset the connection flags

SYN: synchronous serial number, the process for establishing a connection

FIN: finish flags to release the connection

 

TCP three-way handshake process text analysis:

In the TCP / IP protocol, TCP protocol provides reliable connectivity services, three-way handshake to establish a connection.

 

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

Second handshake: server receives a SYN packet, must confirm the customer SYN (ack = j + 1), while themselves sends a SYN packet (syn = k), i.e., SYN + ACK packet, then the server enters a state SYN_RECV;

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 state, complete the three-way handshake.

 

Why do we need three-way handshake to establish a connection?

In order to initialize the initial value of the Sequence Number

Both sides should inform each other their initialization Sequence Number communicate with each other, as to the value of future serial data communication, in order to ensure that the application layer receives the data transfer will not cause problems on the network and out of order, that will use TCP the number to splice data, so the server after postback after his Sequence number that is second handshake, also need to send a confirmation message to the server to inform the server, the client has received the Sequence Numbner initialization of the server.

 

TCP four waved process text analysis:

TCP uses four times and waved to release the connection

The first wave: Client sends a FIN, for closing the data transfer Client Server tenderer, Client enters FIN_WAIT_1 state;

Second wave: Server receives the FIN, ACK to send a Client, the acknowledgment number for the receipt number +1 (the same SYN, FIN a occupy a sequence number), Server enters CLOSE_WAIT state;

Third Wave: Server sends a FIN, for closing the Client Server data transfer, LAST_ACK Server enters state;

The fourth wave: the Client receives the FIN, Client enters TIME_WAIT state, and then sends an ACK to the Server, for the receipt of the acknowledgment number number + 1, Server enters the CLOSED state, four complete wave.

 

Why would a client TIME_WAIT state 2MSL time before the CLOSED state?

  1. To ensure there is enough time to let the other party receives an ACK packet (if passive shutdown that do not receive the ACK packet will trigger the passive end retransmission FIN packet, a return to exactly 2 MSL time)
  2. Avoid confusion connect the old and new

 

Why do I need to disconnect the four-way handshake?

Because full-duplex, the sender and recipient need to FIN packets and ACK packets

 

The reason a large number of server status CLOSE_WAIT

The other socket connection is closed, we are busy to read or write, did not close the connection

  1. Check the code, especially code to release resources
  2. Check the configuration, particularly the thread configured to process the request (probably not very reasonable)

 

Guess you like

Origin www.cnblogs.com/deepSleeping/p/11619886.html