| Crates.io | blitz-ws |
| lib.rs | blitz-ws |
| version | 0.1.0 |
| created_at | 2025-07-15 06:57:02.591864+00 |
| updated_at | 2025-07-15 06:57:02.591864+00 |
| description | Minimal stream-based WebSocket library |
| homepage | |
| repository | https://github.com/Risuleia/blitz |
| max_upload_size | |
| id | 1752693 |
| size | 204,509 |
Lightweight stream-based WebSocket implementation for Rust, inspired from Tungstenite.
use std::net::TcpListener;
use std::thread::spawn;
use blitz::accept;
/// A WebSocket echo server
fn main () {
let server = TcpListener::bind("127.0.0.1:9001").unwrap();
for stream in server.incoming() {
spawn (move || {
let mut websocket = accept(stream.unwrap()).unwrap();
loop {
let msg = websocket.read().unwrap();
// We do not want to send back ping/pong messages.
if msg.is_binary() || msg.is_text() {
websocket.send(msg).unwrap();
}
}
});
}
}
Take a look at the examples section to see how to write a simple client/server.
Blitz
NOTE: blitz exposes primitives, not batteries. For a higher-level abstraction with full async support and production-ready integrations, consider using frameworks like tokio-tungstenite instead. tokio-tungstenite.
Blitz implements key parts of RFC6455, including:
Blitz supports multiple optional TLS and utility features via Cargo:
native-tlsnative-tls-vendoredrustls-tls-native-rootsrustls-tls-webpki-rootsChoose the one that is appropriate for your needs.
By default no TLS feature is activated, so make sure you use one of the TLS features, otherwise you won't be able to communicate with the TLS endpoints.
examples/echo.rs: Simple WebSocket echo server
examples/client.rs: Basic WebSocket client using TcpStream
examples/tls.rs: Connecting via TLS with native-tls or rustls
Blitz supports permessage-deflate via the flate2 crate and the rust_backend feature.
Compression is not enabled by default. You must explicitly negotiate it during the handshake if you want it.
Blitz is experimental but aims for clarity and completeness. Contributions are welcome — especially:
Please file issues or PRs on GitHub.
Licensed under either of: