websocket-client-async

Crates.iowebsocket-client-async
lib.rswebsocket-client-async
version0.1.4
sourcesrc
created_at2022-01-28 14:06:09.881874
updated_at2022-03-20 11:46:38.985155
descriptionAsynchronous websocket client.
homepage
repositoryhttps://github.com/luyikk/websocket-client
max_upload_size
id523088
size49,393
(luyikk)

documentation

https://docs.rs/websocket-client

README

#websocket client

async fn test_websocket()->anyhow::Result<()> {
    wasm_logger::init(wasm_logger::Config::default());

    let (tx, rx) = futures_channel::oneshot::channel();

    let ws = websocket_client::WebSocketClient::connect(
        "127.0.0.1:8888",
        |_, ws, mut reader| async move {
            console_log!("connect websocket server ok");

            let mut buf = Vec::new();
            for _ in 0..1000 {
                reader.read_until(255, &mut buf).await?;
                console_log!("{:?}", buf);
                ws.send_all_ref(&buf).await?;
                buf.clear();
            }
            console_log!("disconnect websocket server");
            tx.send(()).unwrap();
            Ok(true)
        }
        (),
    )
    .await?;
    
    for i in 0..=254 {
        ws.send_all(vec![0, 1, 2, 3,i, 255]).await?;
    }
    rx.await?;
    console_log!("finish");
    Ok(())
}

Commit count: 12

cargo fmt