Crates.io | monoio-tungstenite |
lib.rs | monoio-tungstenite |
version | 0.2.1 |
created_at | 2025-07-25 12:32:55.843199+00 |
updated_at | 2025-08-09 06:17:41.018751+00 |
description | Asynchronous WebSocket implementation for monoio runtime, adapted from tungstenite. |
homepage | |
repository | https://github.com/pikanohup/monoio-tungstenite |
max_upload_size | |
id | 1767575 |
size | 383,242 |
Lightweight, asynchronous WebSocket implementation for monoio
runtime, adapted from tungstenite-rs
.
use monoio::{
io::{sink::SinkExt, stream::Stream},
net::TcpListener,
};
use monoio_tungstenite::accept;
/// A WebSocket echo server.
#[monoio::main]
async fn main() {
let server = TcpListener::bind("127.0.0.1:9001").unwrap();
while let Ok((stream, _)) = server.accept().await {
monoio::spawn(async move {
let mut websocket = accept(stream).await.unwrap();
while let Some(Ok(msg)) = websocket.next().await {
// We do not want to send back ping/pong messages.
if msg.is_binary() || msg.is_text() {
websocket.send_and_flush(msg).await.unwrap();
}
}
});
}
}
For more examples, please refer to the examples/
directory.
[!IMPORTANT] This project was initially developed for personal use and has not been battle-tested in large-scale production environments. Please use it with caution, especially in production systems.
This crate offers a native WebSocket implementation for monoio
, based on the widely-used and reliable tungstenite-rs
. Instead of relying on IntoPollIo
to simply wrap and reuse tokio-tungstenite
or other poll-based libraries, it is built directly on monoio
's native IO model (AsyncReadRent
/AsyncWriteRent
), fully utilizing io_uring
's capabilities while ensuring seamless ecosystem integration.
monoio-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.
Please note that permessage-deflate
is not supported at this time.
monoio-tungstenite
passes the Autobahn Testsuite. It is also covered by internal unit tests as well as possible.
This project is dual-licensed, allowing you to choose between either the MIT License or the Apache-2.0 License at your option.
For details on third-party library attributions, please see the NOTICE file.