tungstenite

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

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

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
68 /100 Good
Development Activity 76
Maintenance 28
Community 68
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
74 /100 Good
Architecture 80
Code Quality 84
Innovation 70
Learning Curve 62

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
69%
MIT

hoop

Monitoring · Security

836

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
64
Dependency
Built with
Go 69%
Clojure 13%
Updated today
Dart
79%
Apache 2.0

LocalSend

Networking

95,370

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
88
Repo Health
61
Technical
78
Dependency
Built with
Dart 79%
Rust 17%
Updated 3 days ago
JavaScript
55%
Other

Lokus

Knowledge Management · Note Taking

829

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

View details
75
Repo Health
75
Technical
64
Dependency
Built with
JavaScript 55%
HTML 21%
Rust 12%
Updated 1 months ago
TypeScript
88%
MIT

Mistle

AI Agents · Developer Tools

95

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

View details
50
Repo Health
76
Technical
70
Dependency
Built with
TypeScript 88%
Rust 11%
Updated 3 weeks ago
Rust
72%
Apache 2.0

Rivet

AI Agents · Developer Tools

6,326

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
87
Repo Health
81
Technical
64
Dependency
Built with
Rust 72%
TypeScript 25%
Updated today
Rust
98%

Stalwart

Collaboration

15,268

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
88
Repo Health
81
Technical
65
Dependency
Built with
Rust 98%
Updated 4 days ago

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