openws-server
WebSocket server in Rust with room-based messaging, private messages, HTTP broadcast, and optional configuration. Designed as a standalone service that any frontend can consume.
Installation
From crates.io (recommended):
From GitHub:
With Docker:
Server starts with configurable host and port via --host / --port flags, environment variables, or openws.toml. Defaults to 0.0.0.0:3000.
Protocol
Connect via WebSocket to ws://localhost:3000/ws. All messages are JSON with a type field.
Client → Server
| type | fields |
|---|---|
join |
room, username |
send |
room, text |
private |
to, text |
ping |
(none) |
Server → Client
| type | fields |
|---|---|
joined |
room, username |
message |
room, from, text, at |
private |
from, text |
user_joined |
room, username |
user_left |
room, username |
error |
code, message |
pong |
(none) |
HTTP endpoints
| method | path | description |
|---|---|---|
| GET | /health |
server health with room/client counts |
| GET | /stats |
per-room breakdown |
| POST | /api/broadcast |
send a message to a room via HTTP |
Broadcast from your backend
The broadcast endpoint requires an API key set in openws.toml (or via OPENWS_API_KEY env var). The endpoint is disabled by default.
Client library
Connect from any JavaScript/TypeScript frontend using the official client:
Or clone from GitHub:
import from "openws-client";
const ws = ;
await ws.;
ws.;
Configuration
Create a openws.toml file or use environment variables. Priority: env var > openws.toml > default.
[]
= "0.0.0.0"
= 3000
[]
= 1000
= 100
= 8192
= 32
[]
= 30
= 10
[]
= ""
CLI flags: --host, --port, --max-clients, --max-rooms, --max-message-size, --max-username-len, --ping-interval, --pong-timeout, --api-key.
Environment variables: OPENWS_HOST, OPENWS_PORT, OPENWS_MAX_CLIENTS, OPENWS_PING_INTERVAL, OPENWS_API_KEY.
Stack
Rust 2021 · Tokio · Axum · serde_json · tracing · config-rs · Docker