A small experimental WebSocket broadcast server CLI program written in Rust. The server accepts WebSocket connections and broadcasts text messages received from one client to all other connected clients.
This repository currently contains only the server module. A separate client implementation is planned for later. You can test the server now using a CLI WebSocket client such as wscat.
- Language: Rust
- Runtime: smol
- WebSocket library: async-tungstenite
- Purpose: simple broadcast server useful for learning or small demos; accepts connections, relays text messages between clients, and gracefully shuts down on Ctrl+C.
- Server module implemented and listening on
127.0.0.1:8080by default. - Client module: not implemented yet.
- Rust toolchain (rustup + cargo). Install via https://rustup.rs/
- Node.js/npm (optional) for
wscatif you want to use it to test the server.
To install wscat (global):
npm install -g wscatFrom the repository root:
# build (optional)
cargo build --release
# run in debug (fast compile & run)
cargo run
# or run the release binary
cargo run --releaseFirst start the broadcast server with the start command:
cargo run startThen open two or more terminals and connect to the running server:
wscat -c ws://127.0.0.1:8080Type a message in one terminal and press Enter — the text should appear in the other connected terminals (the message sender does not receive its own message back).
Example session:
- Terminal A:
wscat -c ws://127.0.0.1:8080 - Terminal B:
wscat -c ws://127.0.0.1:8080 - In A:
hello everyone-> B receiveshello everyone
When you press Ctrl+C in the server terminal, the server will attempt a graceful shutdown and notify connected clients with a close frame.
- If you see an error that the address is in use, either stop the process using that port or change the bind address/port in
src/server/mod.rs. - If
wscatis not connecting, verify the server is running and that you used127.0.0.1rather thanlocalhost(the server binds to the loopback address in the current implementation).
- Implement a client module in Rust (WebSocket client library).
- The server currently uses
smoland channels for brokered broadcasting. The registry limits client id to 0..=255 (u8). Consider increasing the id type if you expect many clients. - See
src/server/mod.rsfor the primary server implementation andsrc/main.rs/src/cli.rsfor how the server is started.