Module std::net::websocket

WebSocket client for bidirectional communication.

Provides a blocking WebSocket client that can send and receive text messages over a persistent connection.

Examples

import std::net::websocket;

fn main() {
    let ws = websocket.connect("ws://localhost:8080/ws");
    ws.send_text("hello");
    let msg = ws.recv();
    msg.free();
    ws.close();
}

Contents

Functions

Function connect

pub fn connect(url: String) -> Conn

Open a WebSocket connection to the given URL.

Examples

let ws = websocket.connect("ws://localhost:8080/ws");

Types

Struct Conn

An open WebSocket connection handle.

Created by calling websocket.connect(url). Use send_text() to send messages and recv() to receive them.

Struct Message

An incoming WebSocket message handle.

Obtained from conn.recv(). Must be freed with free() when no longer needed.

Traits

Trait ConnMethods

Methods available on a WebSocket Conn.

Methods

fn send_text(self: Conn, msg: String) -> i32 fn recv(self: Conn) -> Message fn close(self: Conn)

Trait MessageMethods

Methods available on a WebSocket Message.

Methods

fn free(self: Message)