Skip to main content
The Protocol field on Client controls how RTP and RTCP packets are carried between the client and the server. Set it before calling Start() or StartRecording().
The field is a pointer to Protocol. Setting it to nil (the default) enables automatic selection.

Transport comparison

Automatic selection (default)

When Protocol is nil, the client first attempts UDP. If no packet arrives within InitialUDPReadTimeout (default 3s), it switches to TCP and calls OnTransportSwitch to notify you of the change.

Forcing a specific transport

To lock in a transport without any fallback, point Protocol at a value:
UDP has the lowest overhead and is preferred on reliable local networks.

Full options example

The example below sets the transport to automatic along with explicit timeout values:
client-play-options/main.go

Tunneling

In addition to the transport protocol, the Tunnel field controls whether RTSP is wrapped inside another protocol:
Tunneling via HTTP or WebSocket adds latency and reduces throughput compared to plain RTSP. Use it only when the network requires it.

Firewall considerations

UDP unicast requires the server to reach the client’s UDP ports for RTP and RTCP. If your client is behind a NAT or firewall that blocks inbound UDP, packets will never arrive and the library will fall back to TCP after InitialUDPReadTimeout. Use TCP directly if you know UDP is blocked.
UDP-multicast requires network infrastructure that supports IGMP snooping and multicast routing. It is generally only available on managed local-area networks.