server
ModuleThe server: an adapter, its hooks, and the error callbacks.
Contents
use utopia_websocket::Server;Rust
pub struct Server<A>A WebSocket server on an Adapter.
Every method forwards to the adapter. A failure is never returned: it is
passed, with the Stage that failed, to each callback registered with
Server::error, in registration order (and dropped when there is
none). Clones share the adapter and the callbacks, so a hook can hold
one to send or close from inside an event.
Rust
use utopia_websocket::{Memory, Server};
let adapter = Memory::new();
let server = Server::new(adapter.clone());
let replies = server.clone();
server.on_message(move |connection, message| {
if message == b"ping" {
replies.send(&[connection], "pong");
}
});
adapter.open(1, &Default::default());
adapter.message(1, b"ping");
assert_eq!(adapter.frames()[0].data, "pong");Also implements
Clone.use utopia_websocket::Stage;Rust
pub enum StageThe step of the server that failed, passed to error callbacks.
Also implements
Display.