Skip to main content

Server

Struct Server 

Source
pub struct Server {
Show 13 fields pub config: ServerConfig, pub resource_limits: ResourceLimits, pub max_relay_sends_per_poll: usize, pub running: bool, pub server_fd: i32, pub connections: Vec<Conn>, pub on_frame_cb: Option<fn(&Frame)>, pub on_connect_cb: Option<fn()>, pub on_publish_cb: Option<fn(conn_id: u64, app: &str, stream_name: &str) -> bool>, pub on_play_cb: Option<fn(conn_id: u64, app: &str, stream_name: &str) -> bool>, pub on_media_cb: Option<fn(u64, FrameType, Option<&str>) -> bool>, pub tls_ctx: Option<TlsCtx>, pub defer_media_relay: bool, /* private fields */
}
Expand description

Server object.

A single Server can bind more than one listener (see Server::listen and Server::listen_tls) — e.g. plaintext RTMP on one port and RTMPS on another. All listeners share the same connections, media relay, and stream cache, so a publisher on one listener is relayed to players on any other listener exactly as if they shared a port. Running two separate Server instances instead would silently split the relay: each instance only relays among its own connections.

Fields§

§config: ServerConfig§resource_limits: ResourceLimits§max_relay_sends_per_poll: usize

Maximum relay send operations allowed in one process_connections pass.

The first eligible frame in a pass is always relayed even when its fan-out exceeds this value, which guarantees forward progress instead of perpetually re-queueing an oversized frame. Later frames are deferred once the accumulated send count would exceed the configured budget.

§running: bool§server_fd: i32

Identifies one bound listener (whichever was bound first) for diagnostics/backward compatibility. When more than one listener is bound, use Server::listener_fds to register every listener with an external readiness loop. Server::poll itself checks every bound listener internally.

§connections: Vec<Conn>§on_frame_cb: Option<fn(&Frame)>

Fired for every audio/video frame on every connection.

§on_connect_cb: Option<fn()>

Fired when a client completes the AMF connect exchange.

§on_publish_cb: Option<fn(conn_id: u64, app: &str, stream_name: &str) -> bool>

When set, must return true to allow publish; false rejects the command.

§on_play_cb: Option<fn(conn_id: u64, app: &str, stream_name: &str) -> bool>

When set, must return true to allow play; false rejects the command.

§on_media_cb: Option<fn(u64, FrameType, Option<&str>) -> bool>

When set, must return true before publisher media is queued for relay.

§tls_ctx: Option<TlsCtx>

TLS context built from config at construction time; used by Server::listen calls. This field stays public for Rust API compatibility so integrators that used to replace server.tls_ctx directly can continue to do so before calling listen().

§defer_media_relay: bool

Hold media relay until the integrator enables it per connection.

Implementations§

Source§

impl Server

Source

pub fn new(config: ServerConfig) -> Result<Self>

Create a new server.

Source

pub fn set_conn_id_base(&mut self, base: u64)

Set the starting value used for auto-generated connection IDs.

Only needed when integrating with something outside this crate that numbers connections independently and must not collide with this Server’s IDs. Prefer Server::listen_tls over running a second Server instance for a second listener — one Server with multiple listeners numbers all of its connections from one counter already, so this is unnecessary in that case. Call right after Server::new.

Panics if base is zero, cannot leave room for an increment, or if any connection ID has already been issued.

Source

pub fn listener_fds(&self) -> Vec<i32>

Return the file descriptor for every currently bound listener.

Use this instead of the legacy Server::server_fd field when an external readiness loop needs to watch a multi-listener Server.

Source

pub fn listen(&mut self, bind_addr: &str) -> Result<()>

Start listening on the given address (“host:port”, default port 1935).

Uses the TLS/plaintext mode selected at construction time via ServerConfig::tls_enabled. Can be called more than once (e.g. to also bind an IPv6 address); every bound listener shares this Server’s connections, media relay, and stream cache. To add a listener with an independent TLS certificate — e.g. plaintext RTMP plus RTMPS on a second port — use Server::listen_tls instead.

Source

pub fn listen_tls( &mut self, bind_addr: &str, cert_file: &str, key_file: &str, ) -> Result<()>

Start an additional RTMPS listener with its own certificate/key, independent of the TLS/plaintext mode passed to Server::new.

Connections accepted here land in the same connections list as every other listener on this Server, so a publisher here is relayed to players on any other listener (plaintext or TLS) and vice versa.

Source

pub fn poll(&mut self, timeout_ms: i32) -> Result<()>

Poll for events (non-blocking).

Source

pub fn stop(&mut self)

Stop the server.

Source

pub fn process_connections(&mut self) -> Result<()>

Process all active connections: drain readable bytes, drive the protocol state machine, relay frames from publishers to players, flush pending writes, and reap closed peers.

Trait Implementations§

Source§

impl Drop for Server

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Server

§

impl !Send for Server

§

impl !Sync for Server

§

impl !UnwindSafe for Server

§

impl Freeze for Server

§

impl Unpin for Server

§

impl UnsafeUnpin for Server

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.