blitz-ws

Crates.ioblitz-ws
lib.rsblitz-ws
version0.1.0
created_at2025-07-15 06:57:02.591864+00
updated_at2025-07-15 06:57:02.591864+00
descriptionMinimal stream-based WebSocket library
homepage
repositoryhttps://github.com/Risuleia/blitz
max_upload_size
id1752693
size204,509
Hreeth Gupta (Risuleia)

documentation

README

Blitz

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.

MIT licensed Apache-2.0 licensed

Documentation

Introduction

Blitz implements key parts of RFC6455, including:

  • WebSocket framing, handshake, masking, and control frames
  • RFC-compliant close codes and opcodes
  • HTTP 1.1 request parsing (handshake only)
  • TLS via native-tls or rustls
  • Optional permessage-deflate compression (via flate2)

Features

Blitz supports multiple optional TLS and utility features via Cargo:

  • native-tls
  • native-tls-vendored
  • rustls-tls-native-roots
  • rustls-tls-webpki-roots

Choose 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.

Design Goals

  • Zero async: Fully synchronous, blocking API
  • Explicit handshake logic and frame state machine
  • No hidden abstractions, futures, or macros
  • Easy to audit, debug, and extend

Example Projects

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

Compression Support

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.

Testing

  • Internal unit tests cover most framing and handshake logic.
  • Autobahn Test Suite compatibility is being targeted (WIP).
  • CI planned for protocol compliance and memory safety.

Contributing

Blitz is experimental but aims for clarity and completeness. Contributions are welcome — especially:

  • Autobahn Test Suite passes
  • Advanced compression support
  • More TLS options (e.g. ALPN)
  • Streaming upgrade support

Please file issues or PRs on GitHub.

License

Licensed under either of:

  • MIT License
  • Apache License, Version 2.0 at your option.
Commit count: 0

cargo fmt