What is User Datagram Protocol (UDP) and How Does It Work?

What is User Datagram Protocol (UDP) and How Does It Work?

UDP(User Datagram Protocol) is a communication protocol that sends data across the internet🌐. Its used for time sensitive application like video streaming, gaming and DNS lookups .It speeds up communications by not formally establishing a connection before data is transferred**.**

Deep dive into UDP | How it works ? 👨‍🏭

  1. It is a connectionless protocol. 🙅‍♂️

    • No handshaking - Unlike TCP, UDP doesn’t establish a dedicated connection before sending data. It transmits data in individual packets/datagrams directly to the destination.

    • Faster but less reliable - There is no guarantee that packets will arrive in order or even arrive at all.

  2. Packet Structure

    • Header - Each UDP packets includes a header with some essential information as listed below :

      • Source port - Port of sending application.

      • Destination Port - Port of receiving application.

      • Length - Length of the UDP packet (data + header).

      • Checksum - A simple error checking mechanism to detect data corruption.

    • Data - It is the actual data being transmitted.

    • Sending data -

      • Packaging data - The sending application packages the data into UDP packets, including appropriate header information.

      • Transmission - Packets are then sent over the internet using Internet protocol.

    • Receiving data -

      • Delivery - The receiving device receives the UDP packets.

      • Processing - Receiving application extracts the data and processes it.

Use cases

  1. Internet of things

  2. Live media streaming

  3. DNS lookups

  4. DTLS (Datagram Transport Layer Security)

and many more**….**

Advantages of UDP -

  1. Fast - It is faster than TCP because there is no connection.

  2. Efficient - Lightweight protocol with less overhead.

  3. Low latency: UDP has minimal latency because it doesn't require connection establishment and acknowledgment processes.

  4. Broadcast and multicast - It can send data to multiple recipients.

  5. Endures packet loss: UDP can deliver data even if it's incomplete.

Disadvantages of UDP -

  1. Biggest drawback is UDP is unreliable. It doesn't guarantee that data packets will reach their destination or arrive in order.

  2. UDP doesn't have a mechanism to detect or correct errors in transmitted data

  3. UDP doesn't adjust its transmission rate based on network conditions, which can lead to packet loss.

  4. UDP is not suitable for applications that require reliable data transmissions, such as file transfers, email, or web browsing.

  5. Hackers can exploit UDP's unreliability to execute a distributed denial-of-service (DDoS) attack.

TCP vs UDP

TCPUDP
SecureUnsecure
Connection orientedConnectionless
SlowFast
Guaranteed transmissionNo guarantee
Used by critical applicationsUsed by real-time applications
Flow ControlNo Flow Control
20 bytes header8 bytes header
Acknowledgement mechanismNo acknowledgement
3 way handshakeNo handshake

Conclusion 🚀

To summarize, TCP and UDP are both important Transport layer protocols. TCP offers dependable, orderly, and error-free data transmission, making it ideal for operations that require precision, such as file transfers and web browsing. UDP, on the other hand, provides quicker, connectionless communication that is excellent for real-time applications such as gaming and video streaming, when speed is critical and minor data loss is acceptable. The exact requirements of the task at hand determine whether TCP or UDP should be used. 😁