The difference between TCP and UDP protocols and their respective application scenarios

Analysis & Answers

TCP

Transmission Control Protocol provides connection-oriented, reliable byte stream services. Before the client and server can exchange data with each other, a TCP connection must be established between the two parties before the data can be transmitted. TCP provides timeout retransmission, discarding duplicate data, data inspection, flow control and other functions to ensure that data can be transmitted from one end to the other.

UDP

User Datagram Protocol is a simple datagram-oriented transport layer protocol. UDP does not provide reliability. It only sends the datagrams passed by the application to the IP layer, but there is no guarantee that they will reach their destination. Since UDP does not need to establish a connection between the client and the server before transmitting the datagram, and there is no mechanism such as timeout retransmission, the transmission speed is very fast. Read it carefully and you will understand.

Basic differences between TCP and UDP

  1. Connection-based vs. connectionless
  2. TCP requires more system resources and UDP requires less;
  3. UDP program structure is relatively simple
  4. Stream mode (TCP) and datagram mode (UDP);
  5. TCP guarantees data correctness, UDP may lose packets
  6. TCP guarantees data order, UDP does not.

UDP application scenarios

  1. datagram oriented approach
  2. Most of the network data is short messages
  3. Have a large number of Clients
  4. No special requirements for data security
  5. The network burden is very heavy, but the response speed is high

Meow Interview Assistant: A one-stop solution to interview questions. You can search the WeChat applet [Meow Interview Assistant]  or follow [Meow Interview Assistant] -> Interview Assistant to  answer questions for free. If you have any good interview knowledge or skills, I look forward to sharing them with you!

Guess you like

Origin blog.csdn.net/jjclove/article/details/127394142