Crates.io | ws-test |
lib.rs | ws-test |
version | 0.11.2 |
source | src |
created_at | 2021-08-25 11:13:53.56674 |
updated_at | 2021-08-25 14:27:22.756756 |
description | Lightweight stream-based WebSocket implementation |
homepage | https://github.com/snapview/tungstenite-rs |
repository | https://github.com/snapview/tungstenite-rs |
max_upload_size | |
id | 442101 |
size | 437,512 |
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.
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.
This library is a work in progress. Feel free to ask questions and send us pull requests.
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.
Permessage-deflate.
Tungstenite is thoroughly tested and passes the Autobahn Test Suite for WebSockets. It is also covered by internal unit tests as good as possible.
Please report bugs and make feature requests here.