Function ws::connect

source · []
pub fn connect<U, F, H>(url: U, factory: F) -> Result<()> where
    U: Borrow<str>,
    F: FnMut(Sender) -> H,
    H: Handler
Expand description

A utility function for setting up a WebSocket client.


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.


use ws::{connect, CloseCode};

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

    move |msg| {
        println!("Got message: {}", msg);