TCP vs UDP
TCP vs UDP
TCP
Transmission Control Protocol
The most commonly used protocol on the internet
It is a connection-oriented stream over an IP network
Guarantees all sent packets reach the destination in the correct order.
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.
Then, 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
Connection-less protocol that is datagram oriented
The only guarantee is the single datagram, which can arrive out of order or not at all
More efficient than TCP
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
Last updated