Skip to content
CryoCryo home
Stdlibnet

net::ws

WebSocket, RFC 6455, over any async transport — so the same code handles ws:// over TCP and wss:// over TLS. It is non-blocking throughout, over one buffered connection.

public module net::ws::frame;
public module net::ws::handshake;
public module net::ws::conn;
FileWhat it holdsImport
connWebSocket<S>, Message, connect, acceptimport std::net::ws::conn;
frameFrame, OpCode, and the frame reader/writer on BufStreamimport std::net::ws::frame;
handshakegenerate_key, compute_acceptimport std::net::ws::handshake;
import std::net::ws;

mut ws: WebSocket<TcpStream> = await ws::connect(conn, host, path)?;
await ws.send_text(Str::new("hello"));

match (await ws.recv()) {
    Result::Ok(msg) => { /* Message::Text / Binary / Close */ }
    Result::Err(e)  => { }
}

SHA-1 and base64 for the accept key are pure Cryo from encoding, so plain ws:// pulls in no crypto dependency at all.