TCP (Transmission Control Protocol) is the most commonly used protocol on the internet. It is a connection-oriented stream over an IP network that guarantees all sent packets reach the destination in the correct order.

A TCP handshake or 3 way handshake occurs between the client and server where the client sends a SYNC (synchronize) request, the server sends back and an ACK (acknowledgment) and sync, and then finally the client sends an ACK back.

Once the TCP Handshake is complete, the client and server exchange data (with an ACK after every packet sent, to confirm that the packet safely reached it’s destination with the correct checksum). Once the client and server are done, the handshake is finished and is closed.

TCP must receive acknowledgment packets from the sender and automatically resends any transmissions loss. This causes delays and makes it slow.

UDP (User Datagram Protocol) is a connection-less protocol that is datagram oriented. The only guarantee is the single datagram, which can arrive out of order or not at all. UDP is more efficient than TCP and used for real-time communication (audio, video) where a little percentage of packet loss rate is preferable to the overhead of a TCP connection.

Quick Takeaways

  • TCP is reliable, UDP is unreliable
  • TCP is stream oriented, UDP is message oriented
  • TCP is slower than UPD, but UDP has some signal loss