View Source ExLibSRT.Server (ExLibSRT v0.1.3)
Implementation of the SRT server.
API
The client API consinsts of the following functions:
start/2- starts the serverstart/3- starts the server with password authenticationstart_link/2- starts the server and links to current processstart_link/3- starts the server with password authentication and links to current processstop/1- stops the serveraccept_awaiting_connect_request/1- accepts next incoming connectionreject_awaiting_connect_request/1- rejects next incoming connectionclose_server_connection/2- stops server's connection to given client
Password Authentication
SRT supports password-based authentication. When using password authentication:
- Password must be between 10 and 79 characters long (SRT specification requirement)
 - Empty string means no password authentication (default behavior)
 - All connecting clients must provide the same password
 
A process starting the server will also receive the following notifications:
srt_server_conn/0- a new client connection has been establishedsrt_server_conn_closed/0- a client connection has been closedsrt_server_error/0- server has encountered an errorsrt_data/0- server has received new data on a client connectionsrt_server_connect_request/0- server has triggered a new connection request (seeaccept_awaiting_connect_request/1andreject_awaiting_connect_request/1for answering the request)
Accepting connections
Each SRT connection can carry a streamid string which can be used for identifying the stream.
To support accepting/rejecting the connection a server sends srt_server_connect_request/0 event.
THe process that started the server is then obliged to either call  accept_awaiting_connect_request/1 or reject_awaiting_connect_request/1.
Not responding in time will result in server's rejecting the connection.
When user rejects the stream, the server respons with 1403 rejection code (SRT wise). While not being to accept in time
results in 1504 (not that the codes respectively are the same of HTTP 403 forbidden and 504 gateway timeout).
Response timeout
It is very important to answer the connection request as fast as possible. Due to how
libsrtworks, while the server waits for the response it blocks the receiving thread and potentially interrupts other ongoing connections.
Summary
Functions
Acccepts the currently awaiting connection request.
Acccepts the currently awaiting connection request and starts a separate connection process
Returns a specification to start this module under a supervisor.
Closes the connection to the given client.
Reads socket statistics.
Rejects the currently awaiting connection request.
Starts a new SRT server outside the supervision tree, binding to given address and port.
Starts a new SRT server binding to given address and port and links to current process.
Stops the server.
Types
@type connection_id() :: non_neg_integer()
@type srt_data() :: {:srt_data, connection_id(), data :: binary()}
@type srt_server_conn() :: {:srt_server_conn, connection_id(), stream_id :: String.t()}
@type srt_server_conn_closed() :: {:srt_server_conn_closed, connection_id()}
@type srt_server_error() :: {:srt_server_error, connection_id(), error :: String.t()}
@type t() :: pid()
Functions
Acccepts the currently awaiting connection request.
@spec accept_awaiting_connect_request_with_handler( ExLibSRT.Connection.Handler.t(), t() ) :: {:ok, ExLibSRT.Connection.t()} | {:error, reason :: any()}
Acccepts the currently awaiting connection request and starts a separate connection process
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec close_server_connection(connection_id(), t()) :: :ok | {:error, reason :: String.t()}
Closes the connection to the given client.
@spec read_socket_stats(connection_id(), t()) :: {:ok, ExLibSRT.SocketStats.t()} | {:error, reason :: String.t()}
Reads socket statistics.
Rejects the currently awaiting connection request.
@spec start(address :: String.t(), port :: non_neg_integer(), password :: String.t()) :: {:ok, t()} | {:error, reason :: String.t(), error_code :: integer()}
Starts a new SRT server outside the supervision tree, binding to given address and port.
One may usually want to bind to 0.0.0.0 address.
Password Requirements
If a password is provided, it must be between 10 and 79 characters long according to SRT specification. An empty string means no password authentication will be used.
@spec start_link( address :: String.t(), port :: non_neg_integer(), password :: String.t() ) :: {:ok, t()} | {:error, reason :: String.t(), error_code :: integer()}
Starts a new SRT server binding to given address and port and links to current process.
One may usually want to bind to 0.0.0.0 address.
Password Requirements
If a password is provided, it must be between 10 and 79 characters long according to SRT specification. An empty string means no password authentication will be used.
@spec stop(t()) :: :ok
Stops the server.
Stopping a server should gracefuly close all the client connections.