ServerHandler

Trait ServerHandler 

Source
pub trait ServerHandler:
    Send
    + Sync
    + 'static {
    // Required methods
    fn on_connect(&self, client_id: ClientId, addr: SocketAddr);
    fn on_disconnect(&self, client_id: ClientId);
    fn on_message(
        &self,
        client_id: ClientId,
        message: WsMessage,
    ) -> Option<WsMessage>;
    fn on_error(&self, client_id: Option<ClientId>, error: String);
}
Expand description

WebSocket Server handler for processing incoming messages

Implement this trait to handle incoming WebSocket messages.

Required Methods§

Source

fn on_connect(&self, client_id: ClientId, addr: SocketAddr)

Called when a client connects

Source

fn on_disconnect(&self, client_id: ClientId)

Called when a client disconnects

Source

fn on_message( &self, client_id: ClientId, message: WsMessage, ) -> Option<WsMessage>

Called when a message is received from a client

Return optional response message

Source

fn on_error(&self, client_id: Option<ClientId>, error: String)

Called when an error occurs

Implementors§