Rust

client

Module

A WebSocket client: connect, send, receive or listen, with event hooks.

Contents

use utopia_websocket::Client;
Rust
pub struct Client

A WebSocket client.

Rust
use utopia_websocket::client::{Client, Options};

let client = Client::new("wss://realtime.example.com/v1/realtime?project=main", Options::default())?;
assert_eq!(client.host(), "realtime.example.com");
assert_eq!(client.port(), 443);
assert_eq!(client.path(), "/v1/realtime?project=main");
assert!(!client.is_connected());

let err = Client::new("not a url", Options::default()).unwrap_err();
assert_eq!(err.to_string(), "WebSocket URL must contain a host");
Also implements Debug.
use utopia_websocket::client::Frame;
Rust
pub struct Frame

A frame received from the server.

use utopia_websocket::client::Options;
Rust
pub struct Options

Client options.

Also implements Default.
use utopia_websocket::client::TransportError;
Rust
pub struct TransportError

A transport failure: an error code and its message.

use utopia_websocket::client::Opcode;
Rust
pub enum Opcode

The opcode of a WebSocket frame.

use utopia_websocket::client::Received;
Rust
pub enum Received

What one receive returned.

use utopia_websocket::client::Transport;
Rust
pub trait Transport: Send

An established WebSocket connection the client reads and writes: tokio-tungstenite on the network (the client's own, made by Client::connect), or one given to Client::attach, such as a scripted connection in tests.

Implemented byNetwork
Rust
pub const NO_CONNECTION: i64 = 5001

The error code of a transport whose connection is gone: Client::listen and Client::receive treat it as the server closing the connection.

Rust
pub const TIMED_OUT: i64 = 110

The error code of a receive that timed out: Client::listen keeps waiting.