Fundamentals 16 min read

Why WebRTC Chooses UDP Over TCP and How RTP/RTCP Keep Streams Smooth

This article explains why real‑time audio/video communication prefers UDP over TCP, compares TCP and UDP characteristics, introduces the RTP and RTCP application‑layer protocols that enable reliable media transport, and provides a quick Wireshark guide for capturing and analyzing RTP/RTCP packets.

Tencent IMWeb Frontend Team
Tencent IMWeb Frontend Team
Tencent IMWeb Frontend Team
Why WebRTC Chooses UDP Over TCP and How RTP/RTCP Keep Streams Smooth

1. Transport Layer Protocols: TCP vs UDP

We all know HTTP runs on TCP, but many developers are less familiar with other transport protocols. TCP provides reliable, connection‑oriented byte‑stream transmission, while UDP offers connection‑less, packet‑oriented, unreliable delivery.

TCP/UDP 4‑layer diagram
TCP/UDP 4‑layer diagram

1.1 TCP and UDP Comparison

TCP is connection‑oriented; UDP is connection‑less.

TCP is a byte‑stream protocol; UDP is message‑oriented.

TCP guarantees reliable, ordered delivery; UDP does not.

1.1.1 UDP is connection‑less, TCP is connection‑oriented

UDP sends data without establishing a connection, while TCP requires a three‑way handshake and a four‑way termination.

UDP vs TCP connection diagram
UDP vs TCP connection diagram

1.1.2 UDP is message‑oriented, TCP is byte‑stream

UDP vs TCP payload diagram
UDP vs TCP payload diagram

UDP passes whole datagrams to the application with minimal processing; TCP treats data as an unstructured byte stream, storing it in buffers and handling flow and congestion control.

1.1.3 UDP is unreliable, TCP is reliable

UDP vs TCP reliability diagram
UDP vs TCP reliability diagram

UDP does not retransmit lost packets, whereas TCP detects loss and performs timeout‑based retransmission to ensure reliable delivery.

1.2 Why Choose UDP for Real‑time Audio/Video

Real‑time media is latency‑sensitive; TCP’s retransmission and congestion control introduce unacceptable delays, while UDP’s low‑overhead, connection‑less nature provides faster delivery despite occasional packet loss.

UDP advantages for real‑time media
UDP advantages for real‑time media

WebRTC uses reliable TCP for signaling but relies on UDP for media transport.

2. Application‑Layer Protocols: RTP and RTCP

UDP alone is insufficient for media; RTP adds sequencing, timestamps, and payload‑type information to support real‑time audio/video.

2.1 RTP Protocol

RTP provides end‑to‑end delivery, packet numbering, timestamps, and payload‑type identification.

Real‑time end‑to‑end transport.

Sequence numbers for loss detection and reordering.

Timestamps for synchronization and jitter calculation.

Payload type to indicate codec.

RTP header fields include version, padding, extension, CSRC count, marker, payload type, sequence number, timestamp, SSRC, and CSRC identifiers.

RTP packet structure
RTP packet structure

2.2 RTCP Protocol

RTCP supplies quality‑of‑service feedback such as Sender Report (SR) and Receiver Report (RR), occupying only about 5 % of bandwidth.

RTP defines two sub‑protocols: RTP and RTCP.

RTCP reports include packet counts, loss statistics, and other metrics to help adjust transmission strategies.

RTCP SR and RR
RTCP SR and RR

2.3 RTP Session Flow Summary

RTP session flow diagram
RTP session flow diagram

An RTP session uses a pair of UDP ports: an even port for RTP packets and the next odd port for RTCP packets.

Application sends media to RTP, which encapsulates it into RTP packets.

RTCP packages control information.

RTP packets are sent to the even UDP port; RTCP packets to the odd port.

2.4 Quick Start with Wireshark to Capture RTP/RTCP

Install Wireshark, capture traffic, filter for UDP, decode UDP as RTP, and inspect RTP headers (payload type, timestamp, SSRC) and RTCP reports.

Wireshark installation
Wireshark installation
Select network interface
Select network interface
Filter UDP packets
Filter UDP packets
Decode as RTP
Decode as RTP
RTP stream view
RTP stream view
RTCP SR/RR view
RTCP SR/RR view

3. Conclusion

Understanding the underlying transport protocols deepens one’s ability to leverage WebRTC’s full potential; merely using the API without this knowledge limits performance optimization.

4. References

RTP specification: https://tools.ietf.org/html/rfc3550

NetworkingWiresharkRTPWebRTCUDPRTCP
Tencent IMWeb Frontend Team
Written by

Tencent IMWeb Frontend Team

IMWeb Frontend Community gathering frontend development enthusiasts. Follow us for refined live courses by top experts, cutting‑edge technical posts, and to sharpen your frontend skills.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.