pub trait Factory {
    type Handler: Handler;
    // Required method
    fn connection_made(&mut self, _: Sender) -> Self::Handler;
    // Provided methods
    fn on_shutdown(&mut self) { ... }
    fn client_connected(&mut self, ws: Sender) -> Self::Handler { ... }
    fn server_connected(&mut self, ws: Sender) -> Self::Handler { ... }
    fn connection_lost(&mut self, _: Self::Handler) { ... }
}Expand description
A trait for creating new WebSocket handlers.
Required Associated Types§
Required Methods§
Sourcefn connection_made(&mut self, _: Sender) -> Self::Handler
 
fn connection_made(&mut self, _: Sender) -> Self::Handler
Called when a TCP connection is made.
Provided Methods§
Sourcefn on_shutdown(&mut self)
 
fn on_shutdown(&mut self)
Called when the WebSocket is shutting down.
Sourcefn client_connected(&mut self, ws: Sender) -> Self::Handler
 
fn client_connected(&mut self, ws: Sender) -> Self::Handler
Called when a new connection is established for a client endpoint. This method can be used to differentiate a client aspect for a handler.
use ws::{Sender, Factory, Handler};
struct MyHandler {
    ws: Sender,
    is_client: bool,
}
impl Handler for MyHandler {}
struct MyFactory;
impl Factory for MyFactory {
    type Handler = MyHandler;
    fn connection_made(&mut self, ws: Sender) -> MyHandler {
        MyHandler {
            ws: ws,
            // default to server
            is_client: false,
        }
    }
    fn client_connected(&mut self, ws: Sender) -> MyHandler {
        MyHandler {
            ws: ws,
            is_client: true,
        }
    }
}Sourcefn server_connected(&mut self, ws: Sender) -> Self::Handler
 
fn server_connected(&mut self, ws: Sender) -> Self::Handler
Called when a new connection is established for a server endpoint. This method can be used to differentiate a server aspect for a handler.
use ws::{Sender, Factory, Handler};
struct MyHandler {
    ws: Sender,
    is_server: bool,
}
impl Handler for MyHandler {}
struct MyFactory;
impl Factory for MyFactory {
    type Handler = MyHandler;
    fn connection_made(&mut self, ws: Sender) -> MyHandler {
        MyHandler {
            ws: ws,
            // default to client
            is_server: false,
        }
    }
    fn server_connected(&mut self, ws: Sender) -> MyHandler {
        MyHandler {
            ws: ws,
            is_server: true,
        }
    }
}Sourcefn connection_lost(&mut self, _: Self::Handler)
 
fn connection_lost(&mut self, _: Self::Handler)
Called when a TCP connection is lost with the handler that was setup for that connection.
The default implementation is a noop that simply drops the handler. You can use this to track connections being destroyed or to finalize state that was not internally tracked by the handler.