README
¶
SRT Server
An SRT server that accepts publish and subscribe connections, routing data from publishers to subscribers on matching stream paths.
Overview
The server implements a pub/sub model where:
- Publishers connect with
publish:/pathto send data - Subscribers connect with
subscribe:/pathto receive data - Data is automatically routed from publishers to all matching subscribers
Features
- Pub/Sub Routing: Automatic stream routing based on path matching
- SRT v4/v5 Support: Both legacy and modern streamid protocols
- AES Encryption: Optional passphrase-based encryption
- Token Authentication: Query parameter-based access control
- Path Prefix Filtering: Restrict streams to specific app paths
- Prometheus Metrics: HTTP and Unix socket endpoints
- Profiling Support: CPU, memory, mutex, block, trace profiling
- Graceful Shutdown: Clean connection termination on SIGINT/SIGTERM
Usage
./server -addr :6000 [options]
Required Flags
| Flag | Description |
|---|---|
-addr |
Listen address (e.g., :6000 or 127.0.0.1:6000) |
Server-Specific Flags
| Flag | Description |
|---|---|
-app |
Path prefix filter for streamid (e.g., /live) |
-token |
Required token query parameter for access control |
-passphrase |
Encryption passphrase for encrypted streams |
-logtopics |
Comma-separated log topics for debugging |
Metrics Flags
| Flag | Description |
|---|---|
-promhttp |
Prometheus HTTP endpoint (e.g., :9090) |
-promuds |
Prometheus Unix socket path |
Profiling Flags
| Flag | Description |
|---|---|
-profile |
Profile type: cpu, mem, allocs, heap, rate, mutex, block, thread, trace |
-profilepath |
Directory to write profile files (default: .) |
SRT Configuration Flags
All flags from contrib/common/flags.go are available for SRT configuration:
- Connection timeouts (
-conntimeo,-peeridletimeo) - Latency settings (
-latency,-rcvlatency,-peerlatency) - Buffer sizes (
-fc,-rcvbuf,-sndbuf) - io_uring configuration (
-iouringenabled,-iouringrecvenabled, etc.) - Lock-free architecture (
-useeventloop,-usepacketring, etc.)
Stream ID Format
SRT v5 (Modern)
Publishers use: publish:/path/to/stream
Subscribers use: subscribe:/path/to/stream
With optional query parameters:
publish:/live/stream1?token=secret123
subscribe:/live/stream1?token=secret123
SRT v4 (Legacy)
Legacy clients without streamid are assigned a path based on their remote address.
Architecture
┌──────────────────────────────────────────────────────────────┐
│ SRT Server │
├──────────────────────────────────────────────────────────────┤
│ ┌──────────────┐ ┌──────────────┐ │
│ │ Publisher │──────▶│ PubSub │──────▶ Subscriber 1 │
│ │ (Writer) │ │ Channel │──────▶ Subscriber 2 │
│ └──────────────┘ │ /live/test │──────▶ Subscriber N │
│ └──────────────┘ │
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ Publisher │──────▶│ PubSub │──────▶ Subscriber │
│ │ (Writer) │ │ Channel │ │
│ └──────────────┘ │ /other/path │ │
│ └──────────────┘ │
└──────────────────────────────────────────────────────────────┘
Connection Handling
handleConnect
Called when a client initiates a connection:
- Parses streamid to determine mode (publish/subscribe)
- Validates token if required
- Validates app path prefix if configured
- Sets passphrase for encrypted connections
- Returns
PUBLISH,SUBSCRIBE, orREJECT
handlePublish
Called when a publisher is accepted:
- Creates or retrieves PubSub channel for the path
- Blocks while publisher sends data
- Removes channel when publisher disconnects
- Logs statistics on completion
handleSubscribe
Called when a subscriber is accepted:
- Looks up existing PubSub channel for the path
- Subscribes to receive data
- Blocks while receiving data
- Logs statistics on completion
Examples
Basic Server
./server -addr :6000
Server with Encryption
./server -addr :6000 -passphrase "my-secret-key"
Server with Access Control
./server -addr :6000 -app /live -token "secret123"
Clients must connect with:
- Path starting with
/live - Token query parameter:
subscribe:/live/stream?token=secret123
Server with Metrics
# HTTP metrics endpoint
./server -addr :6000 -promhttp :9090
# Unix socket metrics (for isolated namespaces)
./server -addr :6000 -promuds /tmp/srt_server.sock
Server with High-Performance Config
./server -addr :6000 \
-fc 102400 \
-rcvbuf 67108864 \
-iouringrecvenabled \
-useeventloop \
-usepacketring
Server with CPU Profiling
./server -addr :6000 -profile cpu -profilepath /tmp/profiles
Building
# Standard build
make server
# Debug build (with symbols for profiling)
make server-debug
Files
| File | Description |
|---|---|
main.go |
Server implementation with pub/sub routing |
Documentation
¶
There is no documentation for this package.
Click to show internal directories.
Click to hide internal directories.