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
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);