Go to file
Dominik Nakamura c101024c28
Add support for rustls as TLS backend (#166)
* Add support for rustls as TLS backend

* Use a "use-*" prefix for the TLS features

* Only enable rustls if native-tls is not enabled

* Allows several TLS components to coexist

* Update docs for rustls mentions

* Enable all features on docs.rs

* Rename TLS feature flags from "use-*" to "*-tls"

* Make native-tls the default

* Move TLS related errors to a separate enum

* Add changelog entry about rustls support

* Fix wrong naming in main error enum

* Simplify docs about tls feature flag usage
2021-02-08 13:58:42 +01:00
.github Enable dependabot 2020-08-19 17:54:20 +02:00
autobahn test: autobahn: correct configuration 2019-05-17 01:51:11 +02:00
examples minor fixes 2020-12-01 19:19:45 +01:00
fuzz Edition 2018, formatting, clippy fixes 2019-08-26 21:05:24 +03:00
scripts test: autobahn: correct configuration 2019-05-17 01:51:11 +02:00
src Add support for rustls as TLS backend (#166) 2021-02-08 13:58:42 +01:00
tests Add support for rustls as TLS backend (#166) 2021-02-08 13:58:42 +01:00
.gitignore Initial commit, mostly working client 2017-01-30 10:22:39 +01:00
.travis.yml travis: force build fail on autobahn failure 2020-01-08 22:42:51 +01:00
CHANGELOG.md Add support for rustls as TLS backend (#166) 2021-02-08 13:58:42 +01:00
Cargo.toml Add support for rustls as TLS backend (#166) 2021-02-08 13:58:42 +01: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 Add support for rustls as TLS backend (#166) 2021-02-08 13:58:42 +01:00
rustfmt.toml chore: apply `fmt` to the whole project 2020-11-17 12:40:52 +01:00

README.md

Tungstenite

Lightweight stream-based WebSocket implementation for Rust.

use std::net::TcpListener;
use std::thread::spawn;
use tungstenite::server::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.

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.

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.