TCP vs UDP

Published by

on

Both TCP and UDP are protocols used in Transport layer which takes charge of transporting data between sender and receiver. From this post, we are going to deep dive into what TCP and UDP is, and compare with each other.

TCP (Transmission Control Protocol)

TCP is a connection oriented protocol which provides reliable, ordered and error-checked delivery of data between applications. Usually it is used with IP, and major internet applications like WWW, FTP, SMTP rely on TCP.

  • Connection-oriented
    • 3 way handshake for opening connection
    • 4 way handshake for closing connection
  • Flow control
    • Controls the speed of data transmission, to avoid receiver’s buffer overflow.
  • Congestion control
    • Controls the rate of data entering the network, keeping the data flow below a rate that would trigger collapse.
  • Reliable transmission
    • TCP uses a sequence number to identify each byte of data. The sequence number identifies the order of the bytes, so that the data can be reconstructed in order at destination.
       The sequence number of the first byte is chosen by the transmitter for the first packet, which is flagged SYN. This number is arbitrary and unpredictable.
  • Timeout-based retransmission
    • When sender transmits the segment, it starts a timer with conservative estimate of the arrival time of the acknowledgement. If ACK doesn’t arrive within the timeout, sender will re-transmit the segment with longer timeout value.
  • Error detection
    • TCP Checksum is being used to assure the correctness.
  • Duplicate/Selective acknowledgment-based retransmission
    • Using Duplicate/Selective Acknowledgements, TCP improves the ability to retransmit the right segment.
    • If there is a lost packet, the receiver will not be able to acknowledge the segments afterwards because it uses cumulative ACKs.
      Hence, the receiver sends ACK back to the sender for the latest successful packet to indicate the packet loss. This duplicate ACK is used as a signal of packet loss, which asks for the sender to retransmit the packet.
    • Along with the duplicate ACK, sometimes the receiver sends Selective ACK (SACK) which provides the information of the received segment.

UDP (User Datagram Protocol)

UDP is a simple connectionless protocol with minimum mechanisms compared to TCP. Since it doesn’t open a connection before sending data, data transmission through UDP is faster than TCP. Usually services that consider speed more than reliability like video streaming uses UDP.
As TCP does, UDP also has checksum field in its header to check errors.

TCP vs UDP

TCPUDP
Connection-oriented protocolConnection-less protocol
Connection by byte streamMessage based protocol
Congestion / Flow control (O)Congestion / Flow control (X)
OrderedNot ordered
SlowerFaster
Reliable data transmissionUnreliable data transmission
TCP packet: SegmentUDP packet: Datagram
HTTP, Email, FTPDNS, Broadcasting
UnicastBroadcast, Multicast

Reference

Leave a comment