Library / SDK
snapview/tungstenite-rs avatar
snapview/tungstenite-rs

tungstenite: the README echo server that stops before its own closing braces

Lightweight stream-based WebSocket implementation for Rust.

2,406 stars305 forksRustApache-2.0

At a glance

What is it?
snapview/tungstenite-rs is a synchronous-first RFC6455 implementation for Rust whose README example, TLS feature layout and published file list each reveal something about what the crate does and does not do for you. The protocol code is small and precise; the decisions it pushes onto you are TLS selection, compression and shutdown handling.
Who is it for?
tungstenite is the right pick when you want RFC6455 handled by a compact, synchronous, event-loop-agnostic layer and are willing to choose a TLS backend yourself. Verify three things before committing: which of the four TLS flags your endpoints need, whether you want platform or vendored trust, and whether the absence of permessage-deflate rules out your payload sizes.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 1 day ago.
What is it written in?
Mainly Rust, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 21, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • snapview/tungstenite-rs2,406 ★ · +13
Star history
Repository2026-09-292026-11-21
snapview/tungstenite-rs2.4k2.4k

13 Stars in the last 53 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The echo server on the front page stops three braces early

The crate opens with a Rust example, and the code fence ends while three scopes are still open. `fn main () {` never closes, the `for stream in server.incoming()` loop never closes, and the `spawn (move || {` closure never closes. Exactly one brace appears, after `loop`, and then the block stops.

rust
use std::net::TcpListener;
use std::thread::spawn;
use tungstenite::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();
                }
            }

What survives is still informative. The listener binds `127.0.0.1:9001` and accepts each connection on its own thread through `tungstenite::accept`, then loops on `websocket.read()`. Every fallible step is `unwrap()`, including the one that decides shutdown: when the far side closes, `read()` returns an error, the unwrap panics, and the sample has no clean exit path of its own. The one piece of deliberate logic is the reply guard, `if msg.is_binary() || msg.is_text()`, which discards ping and pong rather than echoing them, matching the comment above it. `accept` is the handshake path, so the snippet only works because `handshake` is the single feature enabled by default.

No TLS runs until one of four cargo features is named

Cargo.toml sets `default = ["handshake"]` and stops there. TLS is a choice among four keys, `native-tls`, `native-tls-vendored`, `rustls-tls-native-roots` and `rustls-tls-webpki-roots`, and the README states the consequence without softening it: by default no TLS feature is activated, so without one of those you cannot communicate with a TLS endpoint. That is a compile-time decision, not a runtime switch, so a dependency line of `tungstenite = "0.30"` reaches `ws://` and nothing else.

The four are not four spellings of one thing. `native-tls-vendored` enables `native-tls` and adds `native-tls-crate/vendored`, building the TLS stack from source rather than linking the platform library. The dependency behind it is renamed in the manifest: a `[dependencies.native-tls-crate]` table with `package = "native-tls"` and `version = "0.2.3"`, so the feature name and the crate name on crates.io do not match. Both rustls keys share an internal `__rustls-tls` feature, double underscore included, which turns on `rustls` and `rustls-pki-types`. That `rustls` dependency is declared `default-features = false` with only `features = ["std"]` at version 0.23.0, and the two rustls keys then diverge on where trust anchors come from: `rustls-native-certs` at 0.8.0 reads the host certificate store, `webpki-roots` at 0.26 ships its own set.

docs.rs renders every feature at once while cargo renders one

`[package.metadata.docs.rs]` sets `all-features = true`. The hosted documentation is therefore built with `native-tls`, `native-tls-vendored`, both rustls variants, `url` and `handshake` switched on together, which is not the configuration the `default` key describes and not one any single application would choose, since the TLS families are meant to be alternatives. Reading docs.rs to learn which items sit behind which flag will mislead you, because everything looks ungated.

The `documentation` field adds a second mismatch by pinning a version: `https://docs.rs/tungstenite/0.30.0` instead of the unversioned path that tracks the newest release. The package version is 0.30.0, so the two agree today and separate the moment the version moves without an edit. The repository has no GitHub releases, so that single Cargo.toml line is the only place the number is written down. The most recent push to the default branch is dated 2026-07-11, and the package declares `edition = "2021"` with `rust-version = "1.85"`. The default branch is `master`, not `main`.

The published crate carries benches and drops the test harness

The `include` list in Cargo.toml covers the `benches`, `src` and `examples` trees, the license files, `README.md` and `CHANGELOG.md`. Every other top-level entry is left out of the artifact, and the omissions are the interesting ones: `autobahn/`, `fuzz/`, `tests/` and `scripts/` are all present in the repository and all absent from the crate. The Autobahn conformance directory the README leans on, and the fuzz targets that share the manifest they live under, reach you only through git.

The trade runs the other way for download weight, since benches ship and benches are what pull `criterion = "0.6"` in as a dev-dependency. The six example files are `autobahn-client.rs`, `autobahn-server.rs`, `callback-error.rs`, `client.rs`, `server.rs` and `srv_accept_unmasked_frames.rs`. Three of those names describe protocol edges rather than the ordinary client and server pair, and `srv_accept_unmasked_frames.rs` points at accepting client frames that arrive unmasked, which strict RFC6455 handling would reject. `callback-error.rs` points the other way, at a callback API that surfaces failures as values, which is the opposite of what the front-page snippet does with its `unwrap()` calls.

permessage-deflate has no key to turn and no crate to fall back on

The README says there is no support for permessage-deflate at the moment and invites pull requests. Nothing in `[features]` argues with it. The feature table covers the handshake, an optional URL parser, two native-tls entries, two rustls entries and the shared internal rustls toggle, and none of them touches compression. The gap is stated in prose and absent from the manifest, so it will not show up as a disabled feature in a dependency tree.

The consequence sits in the framing layer rather than in configuration. Compression under RFC6455 is negotiated per connection through the `permessage-deflate` extension, so a tungstenite peer has nothing to offer even where the other end would accept it. Large text and binary payloads go out at their uncompressed size, and the manifest offers no flag to try before you decide that matters. Anyone who needs compression has to arrange it somewhere other than this crate.

The synchronous shape is the product and async readers get pointed next door

A note near the top calls tungstenite a barebone for building reliable networking applications and sends anyone who wants non-blocking sockets and full-duplex communication to `tokio-tungstenite`, the async sibling in the same organization. The Introduction describes the same shape: synchronous usage like `TcpStream` alongside asynchronous usage, protocol internals abstracted away but still reachable for full control, and easy integration into third-party event loops with MIO named explicitly. Integration is a stated goal here, not an add-on.

The dependency table matches that framing. Four crates are unconditional: `bytes` at 1.9.0, `rand` at 0.10.2, `log` at 0.4.8 and `thiserror` at 2.0.7. Five are optional: `data-encoding` 2, `http` 1.0, `httparse` 1.3.4, `sha1` 0.11.0 and `url` at 2.1.0, the first four gathered behind the default `handshake` key and `url` sitting alone behind a key of its own. The handshake group is the interesting shape: the accept path drags in an HTTP parser, an HTTP type library, base64 encoding and SHA-1, which is what RFC6455 requires for the opening handshake and is why disabling the default is rarely the right move.

Two license files, one dual expression, and links that only resolve on the site

Cargo.toml declares `license = "MIT OR Apache-2.0"`, and both `LICENSE-MIT` and `LICENSE-APACHE` sit at the repository root. The README references them as `[](./LICENSE-MIT)` and `[](./LICENSE-APACHE)`, relative paths that resolve for anyone reading the page on GitHub and resolve to nothing for anyone reading the same text as a crate README or a plain text copy, where there is no repository directory to point at. The visible badge row links out to crates.io, the Actions workflow and docs.rs; the two license links are the only local ones.

The dual SPDX expression and the two files coexist without a note about which applies where. Downstream users who follow the expression get their choice of either license, while users who follow the badges land on a path that only works in one context. Nothing in the manifest is ambiguous, and nothing in the README is either, which is exactly why the mismatch is easy to miss.

Editorial conclusion

tungstenite is the right pick when you want RFC6455 handled by a compact, synchronous, event-loop-agnostic layer and are willing to choose a TLS backend yourself. Verify three things before committing: which of the four TLS flags your endpoints need, whether you want platform or vendored trust, and whether the absence of permessage-deflate rules out your payload sizes. Also read the version-pinned docs.rs URL in Cargo.toml before trusting the hosted documentation. Pass it by if you wanted a batteries-included async client, since the README itself sends that case to tokio-tungstenite.

Frequently asked questions

Which TLS feature do I need to enable in tungstenite?

One of `native-tls`, `native-tls-vendored`, `rustls-tls-native-roots` or `rustls-tls-webpki-roots`. Cargo.toml enables only `handshake` by default, so a build without one of these four cannot communicate with a TLS endpoint.

Does snapview/tungstenite-rs support permessage-deflate compression?

No. The README states there is no support for permessage-deflate at the moment, and no key in the feature table covers compression.

What Rust version does tungstenite 0.30.0 require?

Cargo.toml sets `rust-version = "1.85"` with `edition = "2021"`, and the `documentation` field points at docs.rs for that exact version, 0.30.0.

Is tungstenite-rs an async WebSocket library for Rust?

It supports both synchronous and asynchronous usage, and the README directs readers who want non-blocking sockets and full-duplex communication to tokio-tungstenite, describing tungstenite as a barebone for building networking applications.

Which directories ship inside the published tungstenite crate?

The include list covers benches, src, examples, the LICENSE files, README.md and CHANGELOG.md. The autobahn, fuzz, tests and scripts directories exist in the repository but are not packaged.

Official sources

  1. Issues
  2. License: Apache-2.0
  3. README
  4. snapview/tungstenite-rs on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/snapview-tungstenite-rs.svg)](https://hysenlabs.com/projects/snapview-tungstenite-rs)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/snapview-tungstenite-rs.svg)](https://hysenlabs.com/projects/snapview-tungstenite-rs)

Was this useful?