• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

benches/25-Apr-2025-203149

examples/25-Apr-2025-238193

src/25-Apr-2025-4,7223,347

.cargo-checksum.jsonD25-Apr-20252.9 KiB11

Android.bpD25-Apr-2025981 3935

CHANGELOG.mdD25-Apr-20255.6 KiB9671

Cargo.lockD25-Apr-202534.9 KiB1,3501,195

Cargo.tomlD25-Apr-20253.2 KiB180147

LICENSED25-Apr-202510.6 KiB202169

LICENSE-APACHED25-Apr-202510.6 KiB202169

LICENSE-MITD25-Apr-20251.1 KiB2117

METADATAD25-Apr-2025403 1817

MODULE_LICENSE_APACHE2D25-Apr-20250

README.mdD25-Apr-20253.2 KiB8765

cargo_embargo.jsonD25-Apr-202543 54

README.md

1# Tungstenite
2
3Lightweight stream-based WebSocket implementation for [Rust](https://www.rust-lang.org/).
4
5```rust
6use std::net::TcpListener;
7use std::thread::spawn;
8use tungstenite::accept;
9
10/// A WebSocket echo server
11fn main () {
12    let server = TcpListener::bind("127.0.0.1:9001").unwrap();
13    for stream in server.incoming() {
14        spawn (move || {
15            let mut websocket = accept(stream.unwrap()).unwrap();
16            loop {
17                let msg = websocket.read().unwrap();
18
19                // We do not want to send back ping/pong messages.
20                if msg.is_binary() || msg.is_text() {
21                    websocket.send(msg).unwrap();
22                }
23            }
24        });
25    }
26}
27```
28
29Take a look at the examples section to see how to write a simple client/server.
30
31**NOTE:** `tungstenite-rs` is more like a barebone to build reliable modern networking applications
32using WebSockets. If you're looking for a modern production-ready "batteries included" WebSocket
33library that allows you to efficiently use non-blocking sockets and do "full-duplex" communication,
34take a look at [`tokio-tungstenite`](https://github.com/snapview/tokio-tungstenite).
35
36[![MIT licensed](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE-MIT)
37[![Apache-2.0 licensed](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](./LICENSE-APACHE)
38[![Crates.io](https://img.shields.io/crates/v/tungstenite.svg?maxAge=2592000)](https://crates.io/crates/tungstenite)
39[![Build Status](https://github.com/snapview/tungstenite-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/snapview/tungstenite-rs/actions)
40
41[Documentation](https://docs.rs/tungstenite)
42
43Introduction
44------------
45This library provides an implementation of WebSockets,
46[RFC6455](https://tools.ietf.org/html/rfc6455). It allows for both synchronous (like TcpStream)
47and asynchronous usage and is easy to integrate into any third-party event loops including
48[MIO](https://github.com/tokio-rs/mio). The API design abstracts away all the internals of the
49WebSocket protocol but still makes them accessible for those who wants full control over the
50network.
51
52Why Tungstenite?
53----------------
54
55It's formerly WS2, the 2nd implementation of WS. WS2 is the chemical formula of
56tungsten disulfide, the tungstenite mineral.
57
58Features
59--------
60
61Tungstenite provides a complete implementation of the WebSocket specification.
62TLS is supported on all platforms using `native-tls` or `rustls`. The following
63features are available:
64
65* `native-tls`
66* `native-tls-vendored`
67* `rustls-tls-native-roots`
68* `rustls-tls-webpki-roots`
69
70Choose the one that is appropriate for your needs.
71
72By default **no TLS feature is activated**, so make sure you use one of the TLS features,
73otherwise you won't be able to communicate with the TLS endpoints.
74
75There is no support for permessage-deflate at the moment, but the PRs are welcome :wink:
76
77Testing
78-------
79
80Tungstenite is thoroughly tested and passes the [Autobahn Test Suite](https://github.com/crossbario/autobahn-testsuite) for
81WebSockets. It is also covered by internal unit tests as well as possible.
82
83Contributing
84------------
85
86Please report bugs and make feature requests [here](https://github.com/snapview/tungstenite-rs/issues).
87