TCP three-way handshake fourth wave understand TCP / IP three-way handshake with the four waving correct posture Why is TCP three-way handshake to establish a connection, why not twice or four times?

 

 Three-way handshake

  The first handshake: a client sends a TCP packet, the SYN flag bit is set to 1, the initial sequence number X, is stored in the header of the sequence number (SEQ) in

   Second handshake: server response acknowledgment packet, the SYN flag bit is set to 1, ACK is set to X + 1, the initial sequence number Y, the stored sequence number in the header

   Third handshake:   a client to the server an acknowledgment packet is confirmed, the SYN flag bit is set to 0, ACK is set to Y + 1, Z is set to the serial number

 

Why is TCP three-way handshake to establish a connection, rather than two or four?

The TCP, transmission control protocol called, is a reliable transport protocol, IP protocol number is 6.

Incidentally, no data transmission principle can not ensure absolutely reliable, three-way handshake only ensure reliable basic needs.

 

 The first handshake to close the server can confirm their message with the client transmitter functions are normal text

The second handshake to confirm their clients send and receive messages and send and receive messages server functions are normal, it considers the connection established

Third, both sides confirmed that the server can communicate

If you do not shake hands for the third time, the server to the client after a request to respond (second handshake), will be granted that connection has been established, and if no response is received C and S do? In this case, C still think the connection is not established, S have established connections to save the necessary resources, if a large number of such cases, S crash.
So third handshake is necessary.

 

 

 

Four waving

Four waving

 

 Four waving

The client will send a FIN to the server, data transmission request to close.

 

When the server receives the FIN to the client, the client sends an ACK, which is equal to the value of the ack FIN + SEQ

 

The server then sends a FIN to the client, tell the client application is closed.

 

When the client receives the server's FIN is a reply ACK to the server. Wherein the values ​​of ack equals FIN + SEQ

 

 

Why four wave?

To ensure that data can be transmitted in full.

When the active side of the passive party received FIN message notification, it merely represents the active side there is no data before sending it to the passive side.

But not necessarily the passive side all the data is sent intact to the active side, so the passive side does not close SOCKET immediately, it may also need to send some data to the active side,

And then send a FIN packet to the active side, take the initiative to tell agreed to close the connection, so in most cases ACK packets and FIN packets are sent separately here.

 

 

  TCP packet format Figure:

 

  There are a few fields need to figure above highlights below:

  (1) NO: Seq number, representing 32 bits, used to identify the TCP byte stream from the source to the destination of transmission, the initiator sends data of this labeling.

  (2) the acknowledgment number: Ack number, accounting for 32, when only the ACK flag bit is 1, the acknowledgment number field is valid, Ack = Seq + 1.

  (3) Flags: a total of six, i.e. URG, ACK, PSH, RST, SYN, FIN, and specific meanings are as follows:

  (A) URG: Urgent Pointer (urgent pointer) effective.

  (B) ACK: acknowledgment number is valid.

  (C) PSH: recipient should be the message to the application layer as soon as possible.

  (D) RST: reset the connection.

  (E) SYN: initiate a new connection.

  (F) FIN: releasing a connection.

 

 have to be aware of is:

  (A) Do not Ack acknowledgment sequence number and ACK flag is confused.

  (B) initiator validator Ack = Req + 1, both ends of the pair.

 

 

references:

  Understand the correct posture TCP / IP three-way handshake with the four waving

  Why is TCP three-way handshake to establish a connection, why not twice or four times?

  

Guess you like

Origin www.cnblogs.com/python-Arvin/p/11758168.html