Function parity_ws::connect[][src]

pub fn connect<U, F, H>(url: U, factory: F) -> Result<()> where
    U: Borrow<str>,
    F: FnMut(Sender) -> H,
    H: Handler

A utility function for setting up a WebSocket client.

Safety

This function blocks until the event loop finishes running. Avoid calling this method within another WebSocket handler. If you need to establish a connection from inside of a handler, use the connect method on the Sender.

Examples

use ws::{connect, CloseCode};

connect("ws://127.0.0.1:3012", |out| {
    out.send("Hello WebSocket").unwrap();

    move |msg| {
        println!("Got message: {}", msg);
        out.close(CloseCode::Normal)
    }
}).unwrap()