Flag bit:
SYN: indicates a connection request
ACK: means confirmation
FIN: means to close the connection
Serial number:
seq: indicates the sequence number of the message
ack: Indicates the confirmation serial number
(1) Three-way handshake as shown:
1~~~The first handshake: Client sets the flag SYN to 1 , randomly generates a value seq=J , and sends the data packet to Server , Client enters
SYN_SENT state, waiting for Server confirmation.
2~~~Second handshake: After the server receives the data packet, the flag bit SYN=1 knows that the client requests to establish a connection, and the server sets the flag bit SYN and ACK to 1 .
ack (number )=J+1 , randomly generate a value seq=K ,
And send the data packet to the Client to confirm the connection request, and the Server enters the SYN_RCVD state.
3~~~The third handshake: After the client receives the confirmation, it checks whether the ack is J+1 and whether the ACK is 1. If it is correct, the flag bit ACK is set to 1 , ack=K+1 ,
And send the data packet to the server , the server checks whether the ack is K+1 , whether the ACK is 1 , if it is correct, the connection is established successfully,
The client and the server enter the ESTABLISHED state, complete the three-way handshake, and then the client and the server can start to transmit data
.
(2) The picture shows four waves of hands:
1++++ Wave for the first time: Client sends a FIN to close the data transfer from Client to Server .
2++++ Wave for the second time: After the server receives the FIN , it sends an ACK to the client , confirming that the serial number is the received serial number + 1 .
3++++ Wave for the third time: The server sends a FIN to close the data transfer from the server to the client .
4++++ The fourth wave: After the client receives the FIN , it then sends an ACK to the server , confirming that the serial number is the received serial number + 1 .