tungstenite

A lightweight, stream-based WebSocket protocol implementation for Rust, runtime-agnostic by design

Library
Cargo
v0.30.0
2,385stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
58/100Fair
Development Activity48
Maintenance16
Community68
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
74/100Good
Architecture80
Code Quality84
Innovation70
Learning Curve62

tungstenite is a low-level RFC 6455 WebSocket implementation for Rust that works over any Read + Write stream rather than committing to a specific async runtime. It handles the handshake, framing, masking, and close-handshake logic itself and exposes a synchronous, blocking-style WebSocket<Stream> type that callers drive by reading and writing messages directly.

Because it makes no assumptions about I/O or concurrency model, tungstenite is most often consumed indirectly through async wrappers such as tokio-tungstenite (Tokio) or async-tungstenite (async-std/smol), which adapt its synchronous core to non-blocking async/await APIs. This split — protocol logic in tungstenite, runtime integration in the wrapper crates — is why it underpins a large share of the WebSocket traffic in the Rust ecosystem.

What You Get

  • A complete RFC 6455 WebSocket implementation: handshake, framing, masking, fragmentation, ping/pong, close codes
  • Runtime-agnostic design that works over any std::io::Read + Write stream, blocking or wrapped for async
  • Optional TLS support via native-tls or rustls (with native-roots or webpki-roots variants)
  • Client and server handshake helpers built on the http crate’s Request/Response types
  • A message-oriented API (Message::Text/Binary/Ping/Pong/Close) instead of raw frame manipulation

Common Use Cases

  • Building an async WebSocket client or server on Tokio via the tokio-tungstenite wrapper
  • Building an async-std or smol WebSocket integration via async-tungstenite
  • Implementing a custom transport (e.g. over a non-standard stream type) where an async-runtime-specific WebSocket crate doesn’t fit
  • Writing a minimal, dependency-light WebSocket client for embedded or constrained environments using blocking I/O

Under The Hood

Architecture - The crate is organized around a protocol/ module implementing the WebSocket state machine and frame codec, a handshake/ module implementing the HTTP Upgrade handshake for both client and server roles, and a top-level WebSocket<Stream> struct in lib.rs that ties buffering (buffer.rs), the stream abstraction (stream.rs), and TLS (tls.rs) together into a single read/write-message interface.

Tech Stack - Pure Rust with a deliberately small dependency set: http/httparse for handshake parsing, sha1/data-encoding for the handshake’s Sec-WebSocket-Accept computation, and optional native-tls-crate or rustls/rustls-pki-types/webpki-roots/rustls-native-certs behind feature flags, so consumers only pull in the TLS stack they actually need.

Code Quality - The tests/ directory covers connection-reset handling, handshake edge cases, write-after-close semantics, and TLS-disabled behavior, and the repo includes an autobahn/ directory wired to the Autobahn WebSocket Testsuite (the standard protocol-conformance test suite) plus a fuzz/ target for handshake/frame fuzzing, which is a strong quality signal for a wire-protocol implementation.

API Design - The core loop is simple: construct a WebSocket from a stream via client()/accept(), then call read()/send() with a Message enum. This synchronous, blocking-shaped API is intentionally minimal at the cost of not being directly usable from async code — that gap is what the tokio-tungstenite/async-tungstenite wrapper crates exist to close, which means new users often need to learn which wrapper crate to reach for rather than using tungstenite directly.

Used by 6 apps in this directory

Go
62%
MIT

hoop

Security · Monitoring

791

A wire-protocol gateway that enforces data masking, command blocking, approval workflows, and full session recording for engineers and AI agents accessing production infrastructure.

View details
86
Repo Health
80
Technical
66
Dependency
Built with
Go62%
Clojure20%
JavaScript10%
Updated yesterday
Dart
80%
Apache 2.0

LocalSend

Networking

88,691

An open-source, cross-platform AirDrop alternative that sends files and messages device-to-device over your local network with no internet, no account, and no cloud server involved.

View details
89
Repo Health
61
Technical
78
Dependency
Built with
Dart80%
Rust17%
Updated today
JavaScript
57%
Other

Lokus

Note Taking · Knowledge Management

774

Local-first note-taking with graph view, canvas & AI plugins—your Markdown files, zero telemetry, blazing-fast Rust performance.

View details
78
Repo Health
75
Technical
65
Dependency
Built with
JavaScript57%
HTML24%
Updated 1 weeks ago
TypeScript
88%
MIT

Mistle

AI Agents · Developer Tools

89

Self-hostable platform for running autonomous coding agents in isolated, credentialless sandboxes with brokered credentials, reusable snapshots, and event-driven triggers.

View details
71
Repo Health
76
Technical
71
Dependency
Built with
TypeScript88%
Rust11%
Updated 1 months ago
Rust
67%
Apache 2.0

Rivet

AI Agents · Developer Tools

6,065

Stateful actors as a primitive for AI agents, real-time collaboration, and durable execution — with in-memory state, WebSockets, queues, and scheduling built in.

View details
86
Repo Health
81
Technical
66
Dependency
Built with
Rust67%
TypeScript29%
Updated today
Rust
98%

Stalwart

Collaboration

14,255

All-in-one secure mail and collaboration server covering IMAP, JMAP, SMTP, CalDAV, CardDAV, and WebDAV in a single memory-safe Rust binary.

View details
89
Repo Health
81
Technical
68
Dependency
Built with
Rust98%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search