Expand description
RustWave
A Lightweight async event-driven WebSocket framework for Rust.
Features:
- Async event-driven WebSocket server and client.
- Rooms.
- Broadcasts.
- Typed Payloads.
- Easy to use.
- Async handlers powered by Tokio.
Example Server usage:
use rustwave::{Server, Result};
#[tokio::main]
async fn main() -> Result<()> {
let server = Server::bind("127.0.0.1:8080");
// Events on the root namespace("/")
server.on("message", |data, ctx| async move {
println!("Client {} say: {}", ctx.get_socket_id(), data);
});
server.run().await?;
Ok(())
}Example Client usage:
use rustwave::{Client, Result};
#[tokio::main]
async fn main() -> Result<()> {
let client = Client::connect("ws://127.0.0.1:8080").await?;
client.on("message", |data| async move {
println!("Client got message: {}", data);
});
client.emit("message", "Hello Server!".to_string()).await?;
client.wait().await;
Ok(())
}RustWave provides an event-based API for building real-time applications.
§Benchmark
§Test Environment
- CPU: Intel(R) Core(TM) i3-3220 CPU @ 3.30GHz
- RAM: 4GB
- OS: Fedora Linux
- Rust Version: 1.94.0
- Build:
cargo run --release
§Echo Benchmark
Client: 10,000 Messages per client: 100 Total Messages: 1,000,000 Test Type: Echo
§Test Result
Message loss: 0 Total time: 8.88s Throughput: 112,587 msgs/sec
Re-exports§
pub use error::Result;pub use error::RustWaveError;
Modules§
Structs§
- Broadcast
Builder - A builder for sending an event to multiple clients, with optional room targeting and sender exclusion.
- Client
- A WebSocket client that connects to a Server (or any compatible WebSocket server) and exchanges events with it.
- Namespace
- Represents a single namespace within the server.
- Payload
- The data carried by an event, either received from a peer/server or about to be sent.
- Peer
Context - A handle representing a single connected client (peer).
- Server
- A WebSocket server. that listens for incoming connections and routes
them to registered
Namespaces based on the connection’s URL path.