monoio-tungstenite

Crates.iomonoio-tungstenite
lib.rsmonoio-tungstenite
version0.2.1
created_at2025-07-25 12:32:55.843199+00
updated_at2025-08-09 06:17:41.018751+00
descriptionAsynchronous WebSocket implementation for monoio runtime, adapted from tungstenite.
homepage
repositoryhttps://github.com/pikanohup/monoio-tungstenite
max_upload_size
id1767575
size383,242
pika (pikanohup)

documentation

https://docs.rs/monoio-tungstenite

README

monoio-tungstenite

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.

Crates.io Docs.rs License Build Status

Introduction

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.

Features

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.

Testing

monoio-tungstenite passes the Autobahn Testsuite. It is also covered by internal unit tests as well as possible.

License

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.

Commit count: 0

cargo fmt