wsrouter
Fast and easy WebSocket message routing for servers and clients.
Overview
wsrouter provides a simple message-based routing layer for WebSocket
servers and clients using a lightweight parser.
Features
server– Enables the WebSocket serverclient– Enables the client-side connectorroute– Provides a simple routing API
Example
Server
# #[tokio::main]
# async fn main() {
use wsrouter::server::Server;
let mut server = Server::new("127.0.0.1:3000".to_string());
server.route("@PING".to_string(), |_, dispatcher| {
dispatcher.send("@PONG".to_string());
});
server.serve().await;
# }
Client
# #[tokio::main]
# async fn main() {
use wsrouter::client::Connector;
let connector = Connector::new("ws://localhost:3000".to_string());
connector.route("@PING".to_string(), |_, dispatcher| {
dispatcher.send("@PONG".to_string());
});
let dispatcher = connector.connect().await;
dispatcher.send("@PING".to_string());
dispatcher.keep_alive().await;
# }