- Notifications
You must be signed in to change notification settings - Fork247
Lightweight stream-based WebSocket implementation for Rust.
License
Apache-2.0, MIT licenses found
Licenses found
snapview/tungstenite-rs
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Lightweight stream-based WebSocket implementation forRust.
use std::net::TcpListener;use std::thread::spawn;use tungstenite::accept;/// A WebSocket echo serverfnmain(){let server =TcpListener::bind("127.0.0.1:9001").unwrap();for streamin server.incoming(){spawn(move ||{letmut websocket =accept(stream.unwrap()).unwrap();loop{let msg = websocket.read().unwrap();// We do not want to send back ping/pong messages.if msg.is_binary() || msg.is_text(){ websocket.send(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 applicationsusing WebSockets. If you're looking for a modern production-ready "batteries included" WebSocketlibrary that allows you to efficiently use non-blocking sockets and do "full-duplex" communication,take a look attokio-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 includingMIO. The API design abstracts away all the internals of theWebSocket protocol but still makes them accessible for those who wants full control over thenetwork.
It's formerly WS2, the 2nd implementation of WS. WS2 is the chemical formula oftungsten disulfide, the tungstenite mineral.
Tungstenite provides a complete implementation of the WebSocket specification.TLS is supported on all platforms usingnative-tls
orrustls
. The followingfeatures 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 defaultno 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 😉
Tungstenite is thoroughly tested and passes theAutobahn Test Suite forWebSockets. It is also covered by internal unit tests as well as possible.
Benches are in./benches.
- Run all with
cargo bench --bench \* -- --quick --noplot
- Run a particular set with, say "e2e", with
cargo bench --bench e2e -- --quick --noplot
Please report bugs and make feature requestshere.
About
Lightweight stream-based WebSocket implementation for Rust.
Topics
Resources
License
Apache-2.0, MIT licenses found
Licenses found
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.