Skip to main content
The Server struct is the entry point for building an RTSP server with gortsplib. It handles incoming TCP connections, optional UDP transports, multicast distribution, and TLS. You control server behavior by implementing one or more ServerHandler* interfaces and assigning them to Server.Handler.

Server fields

RTSPAddress is the only required field. All other fields are optional.

Transport

Timeouts

Security

Tuning

Handler

Handler pattern

The handler is an ordinary Go struct pointer assigned to Server.Handler. The server checks at runtime which ServerHandler* interfaces the struct implements and calls only those methods. None of the interfaces are required — implement only the callbacks relevant to your use case.

Basic server setup

The following example creates a server that accepts a single publisher and relays the stream to any number of readers.
server/main.go

Server lifecycle methods

Next steps

Handling requests

Implement handler callbacks to control how your server responds to DESCRIBE, ANNOUNCE, SETUP, PLAY, and RECORD.

Authentication

Validate publisher and reader credentials using VerifyCredentials.

Security

Enable TLS (RTSPS) and automatic SRTP/SRTCP encryption.