Designed for [HAWK](https://github.com/euvoor/hawk) Example ======= ```rust use tokio::net::TcpListener; use http_rs::Http; use websocket_rs::{ Websocket, Opcode }; #[tokio::main] async fn main() -> Result<(), Box> { let mut listener = TcpListener::bind("127.0.0.1:8080").await?; println!("Listening for websocket connections on 127.0.0.1:8080"); while let Ok((stream, addr)) = listener.accept().await { tokio::spawn(async move { println!("New connection from {:?}", addr); let mut http = Http::new(stream); if let Some(req) = http.next().await { if req.for_websocket() { let mut ws = Websocket::new_with_key( http.transport.into_inner(), req.headers.get("sec-websocket-key").unwrap().to_string() ); while let Some(msg) = ws.next().await { println!("{:?}", msg); if msg.opcode == Opcode::Text { let response = format!("Received: {:?}", msg.payload); ws.send_text(response).await.unwrap(); } } println!("Client from {:?} disconnected", addr); } } }); } Ok(()) } ``` TODO ==== - [*] Handle errors properly - [x] Receive opcode TEXT - [x] Pong when Ping is received - [x] Handle all payload lengths (**le 125**, **=126**, **=127**) - [x] Mask key - [x] Close websocket connection - [x] Read fragmented frames - [x] Extract websocket to its own crate - [ ] Add binary support - [ ] Send fragmented frames when the size reaches a treshold - [ ] Schedule ping/pong - [ ] Pong with application data included in ping - [ ] Keep track of connected clients