Bug: 288303428

Clone this repo:
  1. 3555ce6 Update Android.bp by running cargo_embargo am: 2edebd26bf by James Farrell · 8 weeks ago main master
  2. 2edebd2 Update Android.bp by running cargo_embargo by James Farrell · 9 weeks ago
  3. ac8a026 Empty merge of Android 24Q2 Release (ab/11526283) to aosp-main-future by Xin Li · 3 months ago
  4. 28c51f2 Upgrade tungstenite to 0.21.0 am: f3862b033b am: a9fa421db3 by Jeff Vander Stoep · 5 months ago
  5. a9fa421 Upgrade tungstenite to 0.21.0 am: f3862b033b by Jeff Vander Stoep · 5 months ago emu-34-2-dev


Lightweight stream-based WebSocket implementation for Rust.

use std::net::TcpListener;
use std::thread::spawn;
use tungstenite::accept;

/// A WebSocket echo server
fn main () {
    let server = TcpListener::bind("").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() {

Take a look at the examples section to see how to write a simple client/server.

NOTE: tungstenite-rs is more like a barebone to build reliable modern networking applications using WebSockets. If you're looking for a modern production-ready “batteries included” WebSocket library that allows you to efficiently use non-blocking sockets and do “full-duplex” communication, take a look at tokio-tungstenite.

MIT licensed Apache-2.0 licensed Crates.io Build Status



This library provides an implementation of WebSockets, RFC6455. It allows for both synchronous (like TcpStream) and asynchronous usage and is easy to integrate into any third-party event loops including MIO. The API design abstracts away all the internals of the WebSocket protocol but still makes them accessible for those who wants full control over the network.

Why Tungstenite?

It's formerly WS2, the 2nd implementation of WS. WS2 is the chemical formula of tungsten disulfide, the tungstenite mineral.


Tungstenite provides a complete implementation of the WebSocket specification. TLS is supported on all platforms using native-tls or rustls. The following features are available:

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

There is no support for permessage-deflate at the moment, but the PRs are welcome :wink:


Tungstenite is thoroughly tested and passes the Autobahn Test Suite for WebSockets. It is also covered by internal unit tests as well as possible.


Please report bugs and make feature requests here.