TCP vs UDP

What is the difference?

Posted by jyaquinas on March 30, 2022 · 1 min read

TCP vs UDP

Both TCP (Transmission Control Protocol) vs. UDP (User/Universal Datagram Protocol) are transport layer protocols of the TCP/IP protocol stack. Both of them use the IP protocol.

TCP

  • Connection orientated protocol
  • Typically used when requires guaranteed message delivery (high reliability)
  • Has built it error recovery and retransmission
  • Sets up connection using a 3-way handshake
    1. Send SYN (synchronize sequence number), informs the server that it wants to establish a connection
    2. The server responds to the client by sending SYN-ACK (acknowledgment)
    3. The client responds to the server with ACK. Once a reliable connection is established, a two-way data transfer is possible

UDP

  • Connectionless protocol (no handshake mechanism)
  • Data can be sent but cannot know whether it was successfully delivered on not (typically for apps that require fast data transfers)
  • Error handling must be done on the receiving side
  • Faster than TCP because there is no connection setup (less network traffic) and does not consume resources on receiving side (does not keep the connection open)