roa-websocket

Crates.ioroa-websocket
lib.rsroa-websocket
version0.5.0-rc
sourcesrc
created_at2020-03-03 15:14:54.50556
updated_at2020-03-20 13:58:33.981582
descriptionwebsocket implementation for roa
homepagehttps://github.com/Hexilee/roa/wiki
repositoryhttps://github.com/Hexilee/roa
max_upload_size
id214945
size10,280
xixi (Hexilee)

documentation

https://docs.rs/roa-websocket

README

Stable Test codecov Rust Docs Crate version Download Version License: MIT

Roa-websocket

This crate provides a websocket endpoint.

Example

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(())
# }
Commit count: 722

cargo fmt