Many articles on the network feel too complicated, I try to simplify the complex! Previous chapter TCP three-way handshake

🔴, in a nutshell, is four sentences:

Client:Send a connection release packet(I want to disconnect),

Server:Reply acknowledgement message(noted, please wait a moment),

Server:Send a connection release packet(I can disconnect),

Client:Reply acknowledgement messageLet’s disconnect.

One, two related knowledge.

1. What is TCP four waves?

A term that corresponds to TCP release connections.

What is the information carried in the TCP header?

2.1 the identifier

Identifier of the TCP header Chinese name A brief description
ACK Confirm a ACK = 1 Indicates that the confirmation number is valid
SYN Synchronization bit SYN = 1 indicates that the packet is a connection request
FIN Stop bit FIN = 1 Indicates that the packet releases the connection

In addition to these three identifiers, there are three that will not be expanded here.

2.2 Serial number and confirmation number

TCP header information Chinese name A brief description
seq (Sequece Number) The serial number saidCurrent TCP datagram dataWhat is the ordinal number of the first byte of
ack (Acknowledgement Number) Confirmation no. saidData receiving endWhat is the serial number of the next data you expect to receive,

It also indicates that the data before the previous serial number has been received

2.3 the brain

👇TCP header information here 👇seq is the sequence number of the first byte of this data

2.4 To figure out the various information carried by the TCP header

Now that you know these concepts, you can use more general terms to expand the four-wave.

Ii. Specific instructions

1. Two roles in TCP?

behavior role
The party that initiates the request The client
Passively receive the connected party The service side

2, TCP four wave process

🔴, in a nutshell, is four sentences:

Client:Send a connection release packet(I want to disconnect),

Server:Reply acknowledgement message(noted, please wait a moment),

Server:Send a connection release packet(I can disconnect),

Client:Reply acknowledgement messageLet’s disconnect.

🔴 and then look at what these symbols mean:

SYNSYN = 1 indicates that the packet is a connection request.

ACKACK = 1 Indicates that the confirmation number is valid.

seqIndicates the sequence number of the first byte of the current TCP datagram data.

ackIndicates the serial number of the next data that the data receiver expects to receive, and also indicates that the data before the previous serial number has been received.

🔴 try presenting it in a table

state role What do you do

Information carried
role state
ESTABLSHED connection has been established The client <=== send and receive data ===> The client ESTABLSHED connection has been established
FIN-WAIT-1 The client Sends the packet released by the connection= = = >

FIN=1 ,seq=u
The service side
FIN-WAIT-1 The client < = = =Reply acknowledgement message Indicates that the request is received

ACK=1,seq=v,ack=u+1
The service side Close-wait Closes the WAIT
FIN-WAIT-2 The client < = = =Sends the packet released by the connection

FIN=1,ACK=1,seq=w,ack=u+1
The service side Last-ack final confirmation
Time-wait WAIT timer The client Send a reply confirming connection release= = = >

ACK =1,seq=u+1,ack=w+1
The service side CLOSE CLOSE
CLOSE CLOSE The client Break even The service side

🔴 show it with pictures (I didn’t draw this picture, I cut it in moOCs)

🔴 why does the client wait 2MSL to enter the CLOSE state after the fourth wave?

2MSL: indicates twice the maximum time for a packet to survive on the network. If the time exceeds MSL, the packet is discarded

To ensure that the server can receive the acknowledgement reply (fourth wave) from the client, if the client enters the CLOSE state after sending the message, but the acknowledgement reply does not reach the server due to the network, the server cannot be shut down properly