This is the first article I participated in beginners’ introduction
1. TCP protocol definition
- Connection-oriented reliable transport
- The source port number and destination port number in the TCP header and the source IP address and destination IP address in the IP packet uniquely determine a TCP connection.
- The two parties must shake hands three times to form a true connection.
Two or three handshakes
SequenceDiagram Client ->> Server: SYN server ->> Client: SYN ACK Client -) Server: ACK
- Ack is the ack number. Generally, the ack number is set to 1, indicating that the ack number is valid
- Syn Requests to establish a connection and sends a SYN packet
Three handshake process
- First: The client sends the initial sequence number (random sequence) and syn=1 request flag
- The second time: the server sends the request flag SYN, confirming the ack, its own number, and the client number +1
- The client sends the ACK id for the third time. Its id = its ID +1 and the ack id of the other side +1
Three, why three handshakes
- Both parties confirm the mechanism to ensure that both parties can send and receive data
Wave four or four times
SequenceDiagram Client ->> Server: FIN server -->> Client: FIN ACK Server -->> Client: FIN client -) Server: ACK
- Fin wants to disconnect
Four waves
- First: The client sends a disconnect request to the server. Fin =1
- Second: The server receives the command, notifies the client that it has received the message, and sends an ACK
- Third time: the server sends the disconnection request like the client and tells me that I also want to separate!!
- Fourth time: The client receives the disconnect request, notifies the server that it has received it, and sends an ACK
Five, why to wave four times
- Purpose: Let the other party’s resources do not release freely