Trait parity_ws::Factory[][src]

pub trait Factory {
    type Handler: Handler;
    fn connection_made(&mut self, _: Sender) -> Self::Handler;

    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) { ... } }

A trait for creating new WebSocket handlers.

Associated Types

type Handler: Handler[src]

Loading content...

Required methods

fn connection_made(&mut self, _: Sender) -> Self::Handler[src]

Called when a TCP connection is made.

Loading content...

Provided methods

fn on_shutdown(&mut self)[src]

Called when the WebSocket is shutting down.

fn client_connected(&mut self, ws: Sender) -> Self::Handler[src]

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,
        }
    }
}

fn server_connected(&mut self, ws: Sender) -> Self::Handler[src]

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,
        }
    }
}

fn connection_lost(&mut self, _: Self::Handler)[src]

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.

Loading content...

Implementors

impl<F, H> Factory for F where
    H: Handler,
    F: FnMut(Sender) -> H, 
[src]

type Handler = H

Loading content...