UDP vs. TCP and which one is used for video streaming
December 16, 2020 by Amber Shafer
If you are weighing the advantages of TCP versus UDP, we will assume that you are already familiar with the seven networking layers and the very important transport layer. As with everything, there are advantages and disadvantages to both protocols. To make an informed decision, it is important to understand the main differences between the two.
Adapted from https://microchipdeveloper.com/tcpip:tcp-vs-udp.
Transmission Control Protocol (TCP)
Transmission Control Protocol is one of the oldest and most established networking protocols, and is widely used by basic Internet applications such as the World Wide Web (HTTP), email (SMTP), File Transfer Protocol (FTP) and many others. They are best suited for applications where accurate and reliable delivery is more important than timeliness.
TCP is designed to deliver a highly reliable end-to-end byte stream over an untrusted network. It “cares” about the quality of the data flow and prioritizes the orderly and reliable delivery of packets. It achieves this through a technique known as Positive recognition with retransmission.
This means that it requires a handshake between hosts, and detects issues with IP packets – whether they’re due to network congestion, load balancing issues, or other unexpected network behavior. If TCP determines that IP packets are missing, redundant, or out of sequence, it will request to retransmit the lost data, correct the out-of-order data, and even reduce network congestion. Once the sequence of packets is compiled in the appropriate order, the TCP receiver passes the data to the receiving application.
Because it prioritizes an accurate and reliable stream, TCP can experience long delays (several seconds) while waiting for out-of-order messages or retransmitting lost messages. As such, it is generally considered unsuitable for real-time transmissions, where timing is more important than packet loss.
User Datagram Protocol (UDP)
However, the UDP is a simple, contactless protocol with minimal mechanisms. It validates data integrity using simple checksums, but does not contain handshakes and offers no guarantees of delivery, ordering, or redundancy protection. Despite its reputation for being unreliable (some jokingly refer to UDP as the Unreliable Datagram Protocol), it has a number of attributes that make it attractive for streaming.
The statelessness makes it ideal for transferring data to large numbers of clients. This is further enhanced by multicast support, which unlocks capabilities such as service discovery and streaming. Finally, its lack of retransmission delays makes it suitable for real-time applications such as Voice over IP (VoIP), online gaming, and live video streaming. The latter also makes it ideal for use with the real-time broadcast protocol.
|A connection-oriented protocol.||Offline protocol.|
|Uses specific handshake protocols (generally, SYN, SYN-ACK, ACK).||No handshake.|
|It ensures that the data is delivered to the destination router, making it reliable.||It does not guarantee that the data will be delivered to the destination.|
|The connection stream is treated as a sequence of bytes.||Messages contain packets that are independent of each other.|
|Messages make their way across the Internet from one computer to another.||UDP does not depend on the connection, so one program can send a lot of packets to another program.|
|The packet sequence has been verified.||The data is processed for access.|
|Slower transmission speed due to rearrangement and retransmission.||Faster because integrity is checked at access time with checksum.|
|It checks for errors and attempts to recover errors.||It performs a basic error check and discards faulty packages without attempting to recover errors.|
|It introduces extensive error checking mechanisms using flow control and data acknowledgment.||It only has one error checking mechanism, which is used in checksums.|
|acknowledges slices.||Do not acknowledge certain chipsets.|
|Header size is 20 bytes.||Header size is 8 bytes.|
|TCP is heavy. It needs three packets to set up a socket connection before sending data.||UDP is lightweight. There is no tracking of contacts, order of messages, etc.|
Adapted from https://www.guru99.com/tcp-vs-udp-understanding-the-difference.html.
Since HTTP communication typically occurs over TCP/IP connections, we tend to see HTTP-based streaming protocols layered over TCP connections. However, modern technologies take advantage of the simplicity and speed of UDP.
* When streaming content to users, RTSP frequently relies on a combination of reliable transmission over TCP (for control) and best efforts over UDP (for content delivery) to render audio/video content to client-side applications before the file is complete. Arrive.
For a closer look at UDP vs. TCP as it relates to WebRTC streaming with Wowza, check out this webinar.
About Amber Schaeffer
Amber has two decades of experience providing a variety of market-leading technology products. She is a research enthusiast and holds an MBA and MA in Marketing from the University of Colorado (CU). Outside of work, you can find… View more