tokio-websockets 0.12.0

High performance, strict, tokio-util based WebSockets implementation
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use futures_util::{SinkExt, StreamExt};
use http::Uri;
use tokio_websockets::{ClientBuilder, Error, Message};

#[tokio::main]
async fn main() -> Result<(), Error> {
    let uri = Uri::from_static("ws://127.0.0.1:3000");
    let (mut client, _) = ClientBuilder::from_uri(uri).connect().await?;

    client.send(Message::text("Hello, world!")).await?;

    while let Some(item) = client.next().await {
        println!("{item:?}");
    }

    Ok(())
}