WebSocket support for Humphrey.

The core Humphrey crate does not support WebSocket connections, but through its WebsocketHandler trait, it can be extended to support them, which is what this crate does.

Features

Installation

The Humphrey WebSocket crate can be installed by adding humphrey_ws to your dependencies in your Cargo.toml file.

Documentation

The Humphrey WebSocket documentation can be found at docs.rs.

Basic Example

```rs use humphrey::App;

use humphreyws::error::WebsocketError; use humphreyws::message::Message; use humphreyws::stream::WebsocketStream; use humphreyws::websocket_handler;

use std::net::TcpStream; use std::sync::Arc;

fn main() { let app: App<()> = App::new() .withwebsockethandler(websockethandler(myhandler)); app.run("0.0.0.0:80").unwrap(); }

fn myhandler(mut stream: WebsocketStream, _: Arc<()>) { let helloworld = Message::new("Hello, World!"); stream.send(hello_world).unwrap();

loop {
    match stream.recv() {
        Ok(msg) => println!("Message: {}", msg.text().unwrap()),
        Err(WebsocketError::ConnectionClosed) => {
            break;
        },
        _ => ()
    }
}

println!("Connection closed");

} ```

Further Examples