commit | 5e60bdae1fe2a230fa2c9f0bc51e1f3ceedcae77 | [log] [tgz] |
---|---|---|
author | James Farrell <[email protected]> | Tue Sep 12 02:05:30 2023 +0000 |
committer | Automerger Merge Worker <[email protected]> | Tue Sep 12 02:05:30 2023 +0000 |
tree | f1a69233964d045689871685e5e1de38ec5049ef | |
parent | cc7338d5e0263447d0d9e451341543dd1656487b [diff] | |
parent | 9e8276fe270c0bf2928ae0504bece54abecbb1ab [diff] |
Add cargo2android.json am: 064f3a280d am: 12d36a4dc5 am: 06e8b88135 am: 9e8276fe27 Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/tungstenite/+/2744719 Change-Id: I415054fd1e5536af0bec688ba65140218b918360 Signed-off-by: Automerger Merge Worker <[email protected]>
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
.
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.
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.