Understanding UDP and TCP Protocols

Feb 20, 2025

Transport Protocols: UDP and TCP

Overview of Transport Protocols

  • Transport protocols operate at the transport layer of the internet's five-layer structure:
    • Application Layer
    • Transport Layer
    • Network Layer
    • Link Layer
    • Physical Layer
  • Purpose of Transport Protocols:
    • Allow multiple applications to use one network connection simultaneously
    • Use of ports (about 65,000 per connection) for communication:
      • Example: Application using Port 12437 to send a message to Port 80.

UDP (User Datagram Protocol)

Characteristics of UDP

  • Packet size:
    • Smaller than TCP (UDP headers: 8 bytes vs TCP headers: 20 bytes)
  • Connectionless:
    • No need to establish a connection before sending data.
  • Control over data transmission:
    • More flexibility in sending data at any time.

Limitations of UDP

  • Error detection:
    • Primitive 16-bit checksum; unreliable, does not recover from errors.
  • No guarantee of packet delivery:
    • Does not resend lost packets.
  • No in-order delivery:
    • Packets may arrive out of order.
  • No congestion control:
    • Will attempt to send all packets even in a busy network.

Conclusion on UDP

  • Lightweight but not reliable.

TCP (Transmission Control Protocol)

Characteristics of TCP

  • Connection-based:
    • Requires a connection to be established via a three-way handshake:
      • Initiator asks to connect.
      • Acceptor replies.
      • Acknowledgement confirms connection establishment.
  • Reliability features:
    • Delivery acknowledgements: Sender gets confirmation that data was received.
    • Retransmission: Resends lost packets after timeout.
    • In-order delivery: Rearranges packets to ensure correct order.
    • Congestion control: Delays transmission during network congestion to minimize loss.

Limitations of TCP

  • Larger header size than UDP due to additional features.
  • Potential latency issues due to congestion control:
    • Example: Real-time applications (e.g., Skype) may experience delays.
  • Higher overhead due to acknowledgements and retransmissions.

Conceptual Differences

  • UDP: Message-oriented (data sent in distinct chunks).
  • TCP: Stream-oriented (continuous flow of data, sender does not slice packets).

Application Scenarios

Text Communication

  • TCP recommended:
    • Reliable, supports in-order delivery, and retransmission.
  • UDP may lead to lost or out-of-order text.

File Downloads

  • TCP preferred:
    • Retransmission of lost parts necessary for file integrity.

Remote Access Protocols (e.g., SSH)

  • TCP used for delivery acknowledgements.

Multimedia Streaming

  • Historically, UDP chosen:
    • Lower overhead, tolerates some packet loss.
  • Increasingly, TCP is being used:
    • Benefits of reliability when bandwidth allows.
  • Security issues:
    • Some firewalls block UDP, necessitating TCP use.

Small Transactions (e.g., DNS lookups)

  • UDP is efficient:
    • Reduces overhead of connection management.

Summary

  • Choose between UDP and TCP based on application requirements.
    • UDP for bandwidth-intensive apps tolerating packet loss.
    • TCP for reliability and ordered delivery.