pub struct Server { /* private fields */ }
Expand description
An SSE server.
Implementations§
Source§impl Server
impl Server
Sourcepub fn add_client(&mut self, client: Sender)
pub fn add_client(&mut self, client: Sender)
Add a client to a server. Sender
can be obtained by calling Body::channel()
.
Sourcepub async fn send_to_clients<B: Into<Bytes>>(&mut self, text: B) -> usize
pub async fn send_to_clients<B: Into<Bytes>>(&mut self, text: B) -> usize
Send some text to the clients. Most often, this text is made using an EventBuilder. This will automatically remove all disconnected clients.
This function returns the number of currently connected clients.
Sourcepub async fn send_heartbeat(&mut self) -> usize
pub async fn send_heartbeat(&mut self) -> usize
Send a heartbeat (empty SSE) to all clients. This does not perform any action, but will prevent your connection being timed out for lasting too long without any data being sent.
This function returns the number of currently connected clients.
Sourcepub fn disconnect_all(&mut self)
pub fn disconnect_all(&mut self)
Disconnect all clients that are currently connected to the server.
Sourcepub fn connections(&self) -> usize
pub fn connections(&self) -> usize
Count the number of currently held connections.
Note that this may be an over-estimate of the number of currently connected clients, as
some clients may have disconnected since the last send_to_clients
or send_heartbeat
(both of which prune the list of connections to those which still have a connected client).