compio-ws 0.3.0

WebSocket library for the compio runtime
Documentation

compio-ws

MIT licensed crates.io docs.rs Check Test

WebSocket library for compio.

This crate provides WebSocket client and server support for compio applications, built on top of the tungstenite WebSocket library. It enables real-time bidirectional communication over TCP connections with optional TLS support.

Features

  • WebSocket client and server support
  • Built on tungstenite
  • TLS/SSL support with multiple backends:
    • native-tls: Platform-specific TLS
    • rustls: Pure Rust TLS implementation
  • Certificate verification options (platform-verifier, native-certs, webpki-roots)

Usage

Use compio directly with ws feature enabled:

cargo add compio --features ws

For secure WebSocket connections (wss://), enable a TLS backend:

cargo add compio --features ws,rustls # or native-tls

Example:

use compio::ws::connect_async;

let (mut ws_stream, _) = connect_async("wss://example.com/socket").await?;

// Send and receive messages
ws_stream.send(Message::text("Hello WebSocket!")).await?;
let msg = ws_stream.next().await.unwrap()?;