The above describes the overall architecture of the TCP protocol, today introduces the TCP protocol's famous three-time handshake and four-time handshake.
The server and client must establish a connection before communicating, which is done through three handshakes, thus ensuring the reliability of the communication.
The steps for the three-time handshake are as follows:
Suppose A is the client, B is the server, and a actively communicates with B, the steps are as follows:
1.A send SYN message and Mark Seq=x,ack=0
2.B after receiving the SYN message, if it can communicate, send a confirmation message, and Mark Seq=y,ack=x+1
3.A after receiving confirmation message, send confirmation message, Mark Seq=x+1,ack=y+1
This establishes the connection, where the presence of the state includes
Endpoint |
State |
Describe |
A, b |
CLOSED |
Connection closed, no in-progress communication |
B |
LISTEN |
Listening status |
B |
SYN RCVD |
B received the connection request but not confirmed |
A |
SYN SENT |
A Send a connection request and wait for confirmation |
A, b |
Established |
Both establish a connection |
The four-time handshake close link is as follows:
The specific steps are as follows:
1.A send fin message, Mark Seq=m
2.B after receiving fin message, send confirmation message, Mark Seq=m+1
Fin messages are also sent after 3.B, labeled Seq=n
4.A after receiving fin message, send confirmation message, Mark Seq=n+1
At this point the two sides are disconnected, and the states involved are
Endpoint |
State |
Describe |
A |
FIN WAIT 1 |
Send a close request, wait for confirmation |
A |
FIN WAIT 2 |
Receipt of B's confirmation request, waiting for the fin message of B |
A, b |
CLOSING |
Both sides try to close simultaneously, waiting for the other party to confirm |
B |
CLOSE WAIT |
Received a close request, has been confirmed |
A |
Time waited |
Complete two-way shutdown, waiting for all packets to die |
B |
Last ACK |
Wait for the last confirmation |
The reason for the 4 handshake is that TCP communication is full-duplex and requires both confirmation.
Some views on TCP/IP protocol (2): TCP protocol