#websocket #io #web #client

websocket-client-async

Asynchronous websocket client

5 releases

0.1.4 Mar 20, 2022
0.1.3 Jan 30, 2022
0.1.2 Jan 30, 2022
0.1.1 Jan 30, 2022
0.1.0 Jan 28, 2022

#28 in WebSocket

Download history 2/week @ 2022-03-06 14/week @ 2022-03-13 36/week @ 2022-03-20 1/week @ 2022-04-03 5/week @ 2022-04-10 20/week @ 2022-04-24 30/week @ 2022-05-01 40/week @ 2022-05-08 85/week @ 2022-05-15 23/week @ 2022-05-22 48/week @ 2022-05-29 25/week @ 2022-06-05 2/week @ 2022-06-19

80 downloads per month

MIT/Apache

19KB
418 lines

#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(())
}

Dependencies

~7–16MB
~289K SLoC