Detailed TCP protocol

1. Introduction to TCP protocol.

The TCP protocol is a connection-oriented and reliable network transport layer protocol. No matter which party sends a message to the other party, there will be a three-way handshake before the message can be sent after the connection is established. And the message sender can confirm whether the message is finally delivered accurately. TCP provides a reliable byte stream service, which transmits data through bytecode.

2. The three-way handshake of TCP protocol.

We can understand the three-way handshake in a popular way through the client and the server. The client needs to send a message to the server. First, the client and the server perform a three-way handshake. The three-way handshake must ensure that both the server and the client know themselves. The read and write functions with the other party are normal, and data transmission can be carried out on this basis.

1. The client sends a SYN to the server, (the client tells the server:'I want to send a message to you'). At this time, if the server receives this message, it means that the client's write has been completed.

2. The server sends SYN+ACK to the client, (the server tells the client:'I have received your message, your write function is normal, I sent you a message, see if my write function is normal' ), if the client receives a message at this time, it means that the write and read functions of the client are normal, and the write function of the server is normal, but the read function of the server has not been verified.

3. The client sends an ACK to the server, (the client tells the server:'Your write function is normal'), and the server receives a message at this time, indicating that the read function of the server is also normal. At this time, whether it is the client The read and wirte functions of the server are still normal, the server agrees to establish a connection at this time, and both parties have opened up resources and can send messages.

 

Three handshake

3. Four waves of TCP protocol.

The four waves of the TCP protocol are actually the release of resources by both parties, and the release of resources must be agreed by both parties, and only one party agrees to release resources is invalid.

1. The client sends a FIN to the server, telling the server:'I want to break up with you'.

2. The server sends a FIN+ACK to the client, telling the client:'OK, I get it'.

3. The server finds that there is really no data to transmit, and sends a FIN to the client, telling the client:'I want to break up with you too'.

4. Based on reliable transmission, the client wants the server to send an ACK, telling the server: "Both parties are determined to break up".

 

Wave four times

Fourth, the characteristics of UDP protocol.

The UDP protocol is connectionless, as long as you know the ip and port number, you can send messages, and you don't need to handshakes to establish a connection. Moreover, the UDP protocol has no confirmation mechanism, and the client does not know whether the message sent by the server is successfully sent. But UDP will send the entire message in the sending message, and will neither split nor merge. The UDP protocol is simple and efficient to send, but it is not very reliable in comparison.

5. The difference between TCP protocol and UDP protocol.

1. TCP is based on connection, UDP has no connection.

2. TCP requires more system resources, while UDP requires less resources.

3. The TCP protocol is a streaming protocol, and UDP is a datagram mode.

4. TCP is reliable, guarantees data transmission, and UDP may lose packets.

5. TCP protocol guarantees the order of data, UDP does not guarantee the order of data.

 

 

 

Guess you like

Origin blog.csdn.net/wzs535131/article/details/108373497