pub struct Server<S, M> { /* private fields */ }
Expand description
Represents our server.
Implementations§
Source§impl<S, M> Server<S, M>
impl<S, M> Server<S, M>
Sourcepub fn bind(addr: &str) -> Result<Self, Box<dyn Error>>
pub fn bind(addr: &str) -> Result<Self, Box<dyn Error>>
Create a new server by binding to a listening TCP port.
Sourcepub fn on_closed(self, cb: fn(&mut Conn<S, M>)) -> Self
pub fn on_closed(self, cb: fn(&mut Conn<S, M>)) -> Self
Setup a callback for closed connections.
This callback will only ever be run, when the client terminates the connection to the server.
Sourcepub fn on_closed_unexpected(self, cb: fn(&mut Conn<S, M>)) -> Self
pub fn on_closed_unexpected(self, cb: fn(&mut Conn<S, M>)) -> Self
Setup a callback for unexpectedly closed connections.
This callback will be run when the connection is closed by the client when the server is receiving a message.
Sourcepub fn on_connection(self, cb: fn(&mut Conn<S, M>)) -> Self
pub fn on_connection(self, cb: fn(&mut Conn<S, M>)) -> Self
Setup a callback for each new connection.
This callback will be run when the server stablishes a new connection with a client, before any messages are recevied.
Sourcepub fn on_error(self, cb: fn(&mut Conn<S, M>, Box<dyn Error>)) -> Self
pub fn on_error(self, cb: fn(&mut Conn<S, M>, Box<dyn Error>)) -> Self
Setup a callback for connection errors.
This callback will be run whenever there is an error attempting to get the next message from a connection, e.g. a bad message that fails to be deserialized.
Sourcepub fn on_message(self, cb: fn(&mut Conn<S, M>, M)) -> Self
pub fn on_message(self, cb: fn(&mut Conn<S, M>, M)) -> Self
Setup a calback for each received message.
This is the main callbcak, which is run every time a connection sends a new message.