Why do TCP three-way handshake, waving four

TCP is a reliable transport in order to address emerging. In order to achieve reliability, TCP do flow control, congestion control, and the establishment of mechanisms to do before closing the connection: three-way handshake, waving four times.

Three-way handshake is to allow the client, server before the connection is established to ensure that each can send, receive messages;

Four waved, too, client, server To ensure that all close to each other and then close the connection.

If established, close the absence of such guarantees before connecting directly send messages or turn off the lead, there will be packet loss and other risks.

(Taken to ensure this does not mean a hundred percent)

That is why the three-way handshake? Instead of two, four?

If client A, the server B, where do analogy with the phone:

  1. A said: Hey, hear me?

  2. (B after listening, knowing you can hear A saying.)

    B replied: Yes. You could hear it?

  3. (A After listening, he will know B can hear his own words spoken, and I could hear B.

    But this time do not know A B can not hear it his own words, so A would also like to reply. )

    A reply: ah, hear.

    In this case A, B will be able to know each other can speak, listen, then you can start chatting (ie start sending data to establish the connection).

If it is two-way handshake

It can be seen from the above example, if only two handshakes, if is shut down when the battery died A, B may not know the speech has been the case.

So, before the connection is established, if you want reliable transmission, we must first ensure mutual normally receive messages.

If a four-way handshake

Four or five more can be, but this is actually a bit redundant. So do three-way handshake can be.

Why is four times waving? And not once, twice, three times?

As in the example above, the client A, the server B in a call:

  1. A said: I'm sleepy, want to sleep.

  2. B replies: OK, so I have some things to tell you.

  3. After B finished, he said: I'm done, you go to sleep, bye.

  4. A reply: ah, good night.

    In this case A, B can hang up.

    Then, A 2 seconds, etc. hung up the phone, while B is also linked to the hear the response, i.e., closes the connection.

If it is once, twice waved

As can be seen from the above example, since there may be words to say B, so that A can not finish to hang.

If it is three times waving

B directly off after goodbye, he would not have to determine the A's did not hear him say before (2-3) words. If A and B do not hear just say goodbye, A may have been holding a phone.

So we have to wait B of A reply.

After the fourth wave, such as why the client after time 2MSL close the connection?

(MSL here is: Maximum Segment Lifetime, the message that is the maximum time span is the longest of any existing packets in the network more than this time will be discarded...)

Ibid., Directly off if A, if B does not receive the fourth wave, he does not know A has not heard his own words spoken.

So B over a period of time did not receive it, will again say goodbye A. A waiting time while the 2MSL, can receive the retransmitted message, so that A can restore the B again. (A, B has a time-out mechanism, if you still have not received will be disconnected.)

Moreover, A direct closed Another risk is this: If the original process A is just another port is occupied by other new process, the new process will be receiving a message from B's.

Guess you like

Origin www.cnblogs.com/eycuii/p/11961229.html