#wasm #websocket #async #async-io

websocket-async-io

AsyncWrite/AsyncRead implementations for websockets

1 stable release

Uses new Rust 2021

1.0.0 Sep 21, 2021

#7 in #async-io

Download history 11/week @ 2022-06-01 2/week @ 2022-06-08 3/week @ 2022-06-22 3/week @ 2022-06-29 1/week @ 2022-07-06 2/week @ 2022-07-13 3/week @ 2022-07-20 3/week @ 2022-07-27 2/week @ 2022-08-03 12/week @ 2022-08-17 3/week @ 2022-08-24 2/week @ 2022-08-31 6/week @ 2022-09-07 32/week @ 2022-09-14

54 downloads per month

MIT/Apache

11KB
184 lines

websocket-async-io

Implementations of AsyncRead and AsyncWrite on top of websockets using web-sys)

Example

async fn run() -> Result<(), std::io::Error> {
    let ws = WebsocketIO::new(([127, 0, 0, 1], 8000).into()).await?;
    let (mut reader, mut writer) = ws.split();

    writer.write_all(&[0, 1, 2, 3, 93]).await?;
    writer.write_all(&[42, 34, 93]).await?;
    writer.write_all(&[0, 0, 1, 2, 93]).await?;

    let mut buf = Vec::new();
    for _ in 0..3 {
        reader.read_until(93, &mut buf).await?;
        console_log!("{:?}", buf);
        buf.clear();
    }

    Ok(())
}

lib.rs:

Implementations of AsyncRead and AsyncWrite on top of websockets using web-sys)

Example

# async fn run() -> Result<(), std::io::Error> {
let ws = WebsocketIO::new("localhost:8000").await?;
let (mut reader, mut writer) = ws.split();

writer.write_all(&[0, 1, 2, 3, 93]).await?;
writer.write_all(&[42, 34, 93]).await?;
writer.write_all(&[0, 0, 1, 2, 93]).await?;

let mut buf = Vec::new();
for _ in 0..3 {
    reader.read_until(93, &mut buf).await?;
    console_log!("{:?}", buf);
    buf.clear();
}

# Ok(())
# }

Dependencies

~8.5MB
~161K SLoC