websocket-async-io

Crates.iowebsocket-async-io
lib.rswebsocket-async-io
version1.0.0
sourcesrc
created_at2021-09-21 15:23:09.137189
updated_at2021-09-21 15:23:09.137189
descriptionAsyncWrite/AsyncRead implementations for websockets
homepage
repositoryhttps://github.com/jakobhellermann/websocket-async-io
max_upload_size
id454459
size31,853
Jakob Hellermann (jakobhellermann)

documentation

README

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

cargo fmt