A Socket.IO v4 client for Rust

socketio-next behaves like the reference JavaScript client: namespaces, auth, acks in both directions, binary data, reconnection with the same backoff, polling and websocket transports. Async on tokio, with an optional blocking API and a Tauri 2 plugin.

What you get

  • socket.io-client 4.8 behaviour
    Namespaces, auth, the same reconnection backoff, connection state recovery; checked against the reference client on the wire.
  • Acks both ways, binary anywhere
    Awaitable acks with a timeout, answers to server callbacks, buffers anywhere in the arguments.
  • Typed state and errors
    ConnectionState, DisconnectReason, LinkInfo and one cloneable Error; messages never contain URLs or query values.
  • Polling, websocket, proxies, TLS
    Upgrade or websocket only, HTTP proxies from the environment, rustls or native-tls, private CAs, OS trust store.
  • Async or blocking
    A tokio client with plain-closure or async handlers, and the same client without async behind a feature.
  • Tauri 2 plugin
    Named clients shared by Rust and the webviews, read-only clients, a URL allow-list and a JS API close to socket.io-client.

Connect, emit, await the ack

Add the crate, build a client with its handlers and connect. connect() resolves once the server accepted the namespace, or fails with the error of that attempt.
Cargo.toml
[dependencies]
socketio-next = "0.1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
main.rs
use std::time::Duration;
use serde_json::json;
use socketio_next::{Client, ClientBuilder, Event};

let client = ClientBuilder::new("http://localhost:3000")
    .auth(json!({ "token": "abc" }))
    .on("chat", |event: Event, _: Client| async move {
        println!("chat: {:?}", event.payload());
    })
    .connect()
    .await?;

client.emit("chat", "hello")?;
let reply = client
    .emit_with_ack("add", vec![json!(1), json!(2)], Duration::from_secs(5))
    .await?;
assert_eq!(reply.arg::<i64>(0)?, 3);