ℹ WHAT IS UDP? CHAPTER 1

UDP (User Datagram Protocol) is a connectionless, lightweight transport protocol that provides fast data transmission with minimal overhead. It's ideal for real-time applications where speed is more important than reliability.

⚡ Fast

Minimal overhead and no connection establishment delays. Data is sent immediately.

📡 Connectionless

No handshake required — data is sent immediately without establishing a connection first.

🎯 Best Effort

No guarantee of delivery, ordering, or duplicate protection. Fire and forget.

📡 UDP COMMUNICATION FLOW CHAPTER 2

Unlike TCP which requires a 3-way handshake, UDP simply fires packets at the destination. No connection setup, no teardown.

CLIENT
SERVER
Send data immediately
No connection setup
UDP Packet (Data) ➡
Receives if lucky
No acknowledgment
No retransmission
if packet lost
⬅ UDP Response (Optional)
Response is optional
Not required by protocol
No handshake. No acknowledgment. No retransmission. Just speed.
📄 UDP HEADER STRUCTURE CHAPTER 3

UDP has a tiny 8-byte header — compared to TCP's 20+ bytes. This is one reason UDP is so fast and efficient.

Source Port
16 bits
Sender's port number (optional)
Destination Port
16 bits
Receiver's port number
Length
16 bits
Total length in bytes (header + data)
Checksum
16 bits
Optional error checking
Data (Variable Length)
The actual payload — can be up to 65,507 bytes
Total Header Size: Only 8 bytes!
⚖ UDP CHARACTERISTICS CHAPTER 4

✅ Advantages

  • Low latency — no connection setup delay
  • Minimal overhead — only 8-byte header
  • No flow control — constant data rate
  • Multicast and broadcast support
  • Simple implementation

❌ Disadvantages

  • No delivery guarantee
  • No ordering guarantee
  • No built-in error detection
  • No congestion control
  • No flow control
⚡ UDP vs TCP COMPARISON CHAPTER 5
Feature UDP TCP
Connection Connectionless Connection-oriented
Reliability Best effort Guaranteed
Ordering Not guaranteed Guaranteed
Speed Very fast Slower (overhead)
Header Size 8 bytes 20+ bytes
Error Checking Optional checksum Full error detection
Handshake None 3-way handshake
Use Cases Gaming, streaming, DNS Web, email, file transfer
📱 COMMON UDP APPLICATIONS CHAPTER 6

DNS (Port 53)

Domain name resolution — fast lookups are more important than reliability. Client retries if no response.

// DNS Query Query: example.com Response: 192.168.1.1 If lost → client retries

Gaming (Port 27015)

Real-time multiplayer games — low latency is critical. A few dropped packets is acceptable.

// Game Packet Player: (x, y, z) Action: shoot/move Timestamp: 1234567890

Streaming (RTP/5004)

Video/audio streaming — missing frames are acceptable. Better to skip than freeze.

// Video Frame Frame data: [binary] Sequence: 001, 002... If lost → skip to next
🔢 COMMON UDP PORTS CHAPTER 7

Network Services

  • 53 — DNS
  • 67 — DHCP Server
  • 68 — DHCP Client
  • 123 — NTP

Gaming

  • 27015 — Steam
  • 25565 — Minecraft
  • 7777 — Terraria
  • 27005 — Source Engine

Streaming

  • 5004 — RTP
  • 5005 — RTCP
  • 1935 — RTMP
  • 8080 — HTTP Alt

System Services

  • 161 — SNMP
  • 162 — SNMP Trap
  • 514 — Syslog
  • 69 — TFTP
💻 UDP PROGRAMMING EXAMPLE CHAPTER 8

Here's a minimal Python UDP server and client demonstrating how simple UDP communication is:

🖥 Python UDP Server
import socket # Create UDP socket sock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM ) sock.bind(('localhost', 8080)) while True: data, addr = sock.recvfrom(1024) print(f"Got: {data} from {addr}") sock.sendto(b"Hello Client", addr)
📱 Python UDP Client
import socket # Create UDP socket sock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM ) # Send message message = b"Hello Server" sock.sendto(message, ('localhost', 8080)) # Receive response data, addr = sock.recvfrom(1024) print(f"Got: {data} from {addr}")