Crates.io | roa-websocket |
lib.rs | roa-websocket |
version | 0.5.0-rc |
source | src |
created_at | 2020-03-03 15:14:54.50556 |
updated_at | 2020-03-20 13:58:33.981582 |
description | websocket implementation for roa |
homepage | https://github.com/Hexilee/roa/wiki |
repository | https://github.com/Hexilee/roa |
max_upload_size | |
id | 214945 |
size | 10,280 |
This crate provides a websocket endpoint.
use futures::StreamExt;
use roa_router::{Router, RouterError};
use roa_websocket::Websocket;
use roa_core::{App, SyncContext};
use roa_core::http::Method;
# fn main() -> Result<(), RouterError> {
let mut app = App::new(());
let mut router = Router::new();
router.end(
"/chat",
[Method::GET],
Websocket::new(|_ctx: SyncContext<()>, stream| async move {
let (write, read) = stream.split();
// echo
if let Err(err) = read.forward(write).await {
println!("forward err: {}", err);
}
}),
);
app.gate(router.routes("/")?);
Ok(())
# }