Three-way handshake, waving the basis of four

To establish a connection - a "handshake"; close the connection - "Wave";

 

Detailed three-way handshake :

      First: the message, A randomly selected terminal to transmit a sequence number B as its initial sequence number;

      Second: B ack end use of the transmitted data packets A to confirm, since the sequence number has been received packets x, is ready to receive packet sequence number x + 1, the ack = x + 1, while B tell a own initial sequence number is seq = y;

      Third: A B-side terminal tells received acknowledgment message and is ready to establish a connection B, A own message sequence number of the entry is x + 1, so seq = x + 1, and the ack = y + 1 is a positive A B is ready to receive the data packet sequence number y + 1 is.

 

Why the A-side and later also sends a confirmation of it?

      To prevent the link has expired request packets suddenly spread to the B-side, resulting in an error.

 

The cause of the so-called "expired link request message" of:

      Normal: A a connection request, the connection request packet loss but does not receive acknowledgment packets from B, then A again retransmit the connection request. B later received a confirmation message and a connection is established. Data transfer is completed after the connection is released.

      A connection request is sent a total of two segments, wherein a first lost, the second terminal B ---- does not reach the "expired link request message";

 

      Exceptions : A sends a connection request, but did not lose, but in some network nodes stranded for a long time, resulting in the delay request packet to B before reaching the end after a connection release. This in itself is already a failure of the segment. But this failure B receives a connection request packet after the mistaken A has issued a new connection request, and then send a confirmation message to the A segment, agreed to establish a connection. Assuming no three-way handshake, as long as a confirmation B, a new connection is established. Now A and did not issue a request to establish a connection, it does not ignore the acknowledgment packet B, it will not send data to B; but B thinks a new transmission link has been established, and has been waiting for data sent by A, B many of the resources wasted on this.

      Three-way handshake can prevent this abnormal phenomenon. Just the case: A does not send an acknowledgment message to the acknowledgment terminal B, A, B can not receive acknowledgment knows A does not require a connection.

     

 

Detailed wave four times:

      Full duplex: data communication allows simultaneous transmission in both directions, while referring to A → B B → A, instantaneous synchronized.

      Simplex: when transmitting data to Party B, Party B to Party A can not be transmitted. (One-way car analogy.)

     

      TCP is a full-duplex, so each direction must be shut down separately, and then sends a FIN party when data transmission is completed to terminate the connection in that direction, but this simply means that receives a FIN party will not receive the data and this party can still send data until the other party to send a FIN.

 

      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, 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 is a three-way handshake to establish a connection, and close the connection is four times waving it?

      This is because the server in the LISTEN state, received after establishing a connection request SYN packet, the SYN ACK and placed in a packet sent to the client.

      And when the connection is closed, receive each other's FIN message that just means the other party no longer send data but also receive data, it may not own all the data are sent to each other, so one's own can close immediately, you can also send some data after to each other, and then send a FIN packet to the other side to agree to close the connection now, therefore, own FIN and ACK generally transmitted separately.

Guess you like

Origin www.cnblogs.com/panweiwei/p/11909209.html