Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

UDP Protocol

UDP Protocol

UDP (User Datagram Protocol) is a simple, connectionless transport layer protocol used to transmit data over a network.

The difference between TCP Unlike TCP, UDP does not provide reliability, ordering, or flow control, but it features low latency and high efficiency, making it suitable for applications with high real-time requirements.


How UDP Works

UDP is a connectionless protocol; no connection needs to be established between the client and server before sending data. Its core function is to quickly transmit data packets.

1. UDP Packet Structure

A UDP packet consists of the following parts:

  1. Source Port: The sender's port number.
  2. Destination Port: The receiver's port number.
  3. Length: The total length of the packet (including header and data).
  4. Checksum: Used to detect whether the packet is damaged (optional).
  5. Data: The data actually transmitted.


2. UDP Data Transmission


Key Features of UDP

  1. Connectionless:

  2. No connection needs to be established; data is sent directly.
  3. - No connection needs to be established; data is sent directly.
    1. Unreliability:

    2. Does not guarantee the arrival, order, and integrity of packets.
    3. - Does not guarantee the arrival, order, and integrity of packets.
      1. Low Latency:

      2. Since no connection establishment and acknowledgment are needed, transmission latency is low.
      3. - Since no connection establishment and acknowledgment are needed, transmission latency is low.
        1. Efficiency:

        2. Low header overhead, suitable for transmitting small data packets.
        3. - Low header overhead, suitable for transmitting small data packets.
          1. Supports Broadcast and Multicast:

          2. Can send packets to multiple receivers.
          3. - Can send packets to multiple receivers.

            Applications of UDP

            UDP is widely used in the following scenarios:


            Advantages and Disadvantages of UDP

            Fixed size, stores elements of the same type.

            1. Low Latency: Suitable for applications with high real-time requirements.
            2. High efficiency: Low header overhead, suitable for transmitting small data packets.
            3. Simple: Simple implementation and low resource usage.

            High efficiency in random access of elements.

            1. Unreliable: Does not guarantee the arrival, order, and integrity of packets.
            2. No Flow Control: May cause packet loss or network congestion.
            3. No Connection Management: Cannot detect connection state.

            Alternatives to UDP

            In some scenarios, the following alternatives can be used:


            In summary, UDP is a simple, connectionless transport layer protocol suitable for applications with high real-time requirements due to its low-latency and efficient data transmission. It is widely used in real-time applications, broadcast and multicast scenarios, but attention must be paid to its drawbacks of unreliability and lack of connection management.