Go to file
Daniel Abramov 47f669dacb minor: re-format the `buffer.rs` 2022-02-03 19:38:04 +01:00
.github Enable dependabot 2020-08-19 17:54:20 +02:00
autobahn tests: rely on Autobahn Suite usage from docker 2021-04-22 19:33:27 +02:00
benches minor: re-format the `buffer.rs` 2022-02-03 19:38:04 +01:00
examples feature: Raw fragment message 2021-11-22 20:33:42 +03:00
fuzz Edition 2018, formatting, clippy fixes 2019-08-26 21:05:24 +03:00
scripts tests: rely on Autobahn Suite usage from docker 2021-04-22 19:33:27 +02:00
src Merge pull request #250 from Voronar/message_raw_frame 2021-12-08 18:29:11 +01:00
tests Add a connector to configure TLS config 2021-07-23 21:26:44 +09:00
.gitignore
.travis.yml tests: rely on Autobahn Suite usage from docker 2021-04-22 19:33:27 +02:00
CHANGELOG.md Update changelog and bump the version 2021-11-03 18:52:13 +01:00
Cargo.toml Update sha-1 requirement from 0.9 to 0.10 2021-12-08 08:04:44 +00:00
LICENSE-APACHE Relicense under MIT + Apache-2.0. 2017-04-11 16:18:09 +02:00
LICENSE-MIT Relicense under MIT + Apache-2.0. 2017-04-11 16:18:09 +02:00
README.md Fixes #230 2021-08-17 15:19:57 +02:00
rustfmt.toml Fix clippy warnings and deprecated settings 2021-07-21 10:43:44 +09:00

README.md

Tungstenite

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("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_message().unwrap();

                // We do not want to send back ping/pong messages.
                if msg.is_binary() || msg.is_text() {
                    websocket.write_message(msg).unwrap();
                }
            }
        });
    }
}

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

Documentation

Introduction

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.

Features

Tungstenite provides a complete implementation of the WebSocket specification. TLS is supported on all platforms using native-tls or rustls available through the native-tls and rustls-tls feature flags. By default no TLS feature is activated, so make sure you use native-tls or rustls-tls feature if you need support of the TLS.

There is no support for permessage-deflate at the moment. It's planned.

Testing

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

Contributing

Please report bugs and make feature requests here.