Why is the three-way handshake / four wave

This is the first look at the TCP protocol format segment

Here Insert Picture Description
A segment (data segment) comprises two portions header (header) and data (Data)

Is to be understood that, Sequence number (32-bit serial number) and Acknowledgement number (32 bit Acknowledge number) of these two fields. Reliable transmission TCP is based on these two fields to achieve.

Although the subject is three-way handshake with the four waving but do not understand the 32-bit serial number Segment_number and Acknowledgement number (32-digit Confirmation Number) can not really understand these two processes.

Sequence number

Start TCP session, initiate a connection to one of a SYN bit, 32-bit random number is generated (data segment), subsequent 32-bit segment number from the previous sequence number + (segment length) starts.

When not, then the data is represented as part of the first position.

Subsequent Sequence number in the TCP header data all referring to the first part of the number.

EG:
32 I the transmitted bit number is 100, the data length is 100,

So next time I send Sequence number should be 200, and then assumed that the data length is 50,

If you want to send a third, then the value of the Sequence number shall be 250.

Figure Figure Figure:
Here Insert Picture Description

Length is not included in the TCP header

Acknowledgement number

Replies received maximum Sequence number + 1, it represents the value expected to be received by the Sequence number.

And in fact the same reason above, for example, received Sequence number is 100, the data length is 100, then we will reply Acknowledgement number = 200.

2 three-way handshake process overview

With the above basis, we'll begin to see the handshake process, TCP three-way handshake connection process is as follows, for convenience of description:

SEQ_NUM representatives TCP header in the Sequence number

ACK_NUM representatives TCP header in the Acknowledgment number

DATA_LEN data representative of the length of segment

SYN (1) ACK (0) SEQ_NUM (0) ACK_NUM (0) DATA_LEN (0) >
<
SYN (1) ACK (1) SEQ_NUM (100) ACK_NUM (1) DATA_LEN (0)

SYN (0) ACK (1) SEQ_NUM (1) ACK_NUM (101) DATA_LEN (0) ====>

Connection start

Connection initiator sends a SYN bit set to 1 and a randomly generated SEQ_NUM_A (32-bit number), sent to the initiator.

Reply initiator is ACK (1) ACK_NUM (SEQ_NUM_A + 1), but also need to SYN bit is set to 1, and then generates a random himself SEQ_NUM_B.

After connecting the initiator receives the last segment, replies ACK (1) ACK_NUM (SEQ_NUM_B + 1), after being received (ACK within) the initiator segment, the connection is established.

There may be doubt

1, Why the emphasis Sequence number and Acknowledgement number?

Also assume that three-way handshake, but is very simple:

SYN (1) ACK (0) >
<
SYN (1) ACK (1)
SYN (0) ACK (1) ====>

Looks good, but in fact due to the transmission network is unreliable, if not Sequence number we can not guarantee the order of the segment received at this time, can not know whether a missing segment

Explanation:
the same is a SYN (1) ACK (1) segment, it may be the case when the connection is established once the sender has been mistaken for the missing segment, even more special.

In the data transfer process, too, the segment is retransmitted, the missing segment, segment 100 th continuously transmitted
without Sequence number as a guarantee that they reach the receiver arrangement combinations errors may or may not reach the recipient

2, then under the protection of 32-bit and 32-bit sequence number acknowledgment number, how to ensure that their message is received then the other side?

This fact is well understood, in fact, sent out on my own this part of Sequence number is the ack to, namely: a go back (actually more to the back (sliding window, fast retransmission, etc.), or a go and more back, but just say here that the simplest case).

SEQ_NUM(100) DATA_LEN(100) >
<
ACK(200)

If it does not receive ack, ack or non-receipt of this segment of the ack, on behalf of the other party did not receive their message. For example, the following example, when we learn that the other party does not receive or send us the last time being have not received the second segment.

At this point you can also distinguish whether the segment received in this connection because after the connection is established we will create a new Sequence number.

SEQ_NUM(100) DATA_LEN(100) >
<
ACK (200)
SEQ_NUM (200) DATA_LEN (100)>
<
ACK(200)

3, it is understandable why the TCP connection handshake is three times.

Party initiates a connection issue SYN, and received ACK, which is twice the transmission network.

Similarly the connected party also issued a SYN, and wait for the other to reply, which is twice the transmission network.

Is not it add up to four times? Reply to the connected party will actually connected party SYN (1) and its own ACK (1) request the merger, so establishing a TCP connection to go through a minimum of only three network transmission.

4, why TCP disconnect requires four, rather than three?

Disconnect the party initiating issued FIN, and received ACK, which is twice the transmission network.

The same was also sent off side FIN, and wait for the other to reply, which is twice the transmission network.

The same logic analysis down, in fact, be transmitted only after three to disconnect the connection, but why do we say four waving it? This is because if upon receipt of FIN, as well as wound up data transmission is not finished, the first reply on FIN ACK, and inform each other I already know what you want to disconnected. After waiting for the transmission is completed, the FIN party is disconnected and then transmitted, to inform himself already disconnected.

But in fact can be "third wave", when you receive FIN, has no data to transmit, it is "waved three times."

Published 90 original articles · won praise 13 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_44030580/article/details/104918787