First, both TCP and UDP protocols run on the transport layer.
UDP protocol: user data packet Protocol
1. UDP is connectionless. That is to say, you do not need to establish a connection before data transmission (of course, there is no link release at the end of data transmission), which reduces the overhead and the latency before data transmission.
2. UDP uses the best delivery effort, but does not guarantee reliable delivery. Therefore, the host does not need to maintain a complex link status table.
3. UDP is for packets. The sender's UDP retains the boundary of the packets sent by the application process without merging or splitting them. That is to say, when the application layer delivers the same number of packets to UDP, UDP sends the same message at a time. At the same time, on the receiver side, UDP User Datagram sent from the IP layer is removed from the header and then delivered to the application process at the application layer. That is to say, UDP delivers a complete packet at a time. Therefore, the packet size must be appropriate to reduce the data transmission efficiency. If the message is too long, you need to shard the packets at the IP layer, which will reduce the efficiency of the IP layer. Conversely, if the message is too short, after UDP delivers it to the IP layer, the IP datagram header is too long, which also reduces the efficiency of the IP layer.
4. UDP has no congestion control
TCP: Transmission Control Protocol
1. TCP is a connection-oriented transport layer protocol. Before using the TCP protocol, you must establish a TCP connection.
2. Each TCP connection can have only two endpoints
3. reliable delivery, because the IP layer only provides transmission without bit errors.
4. Full Duplex Communication.
5. byte stream oriented. In TCP, "stream" refers to the byte sequence that flows into or out of the process.
Differences Between TCP and UDP protocols