[go: up one dir, main page]

Crate ewebsock

Source
Expand description

A WebSocket client library that can be compiled to both native and the web (WASM).

Usage:

let options = ewebsock::Options::default();
let (mut sender, receiver) = ewebsock::connect("ws://example.com", options).unwrap();
sender.send(ewebsock::WsMessage::Text("Hello!".into()));
while let Some(event) = receiver.try_recv() {
    println!("Received {:?}", event);
}

§Feature flags

  • tokio — Opt-in to the tokio executor.

    This adds a lot of dependencies, but may yield lower latency and CPU usage when using ws_connect.

    Will ignore any ControlFlow::Break returned from the on_event callback.

Structs§

Options
Options for a connection.
WsReceiver
Receiver for incoming WsEvents.
WsSender
This is how you send WsMessages to the server.

Enums§

WsEvent
Something happening with the connection.
WsMessage
A web-socket message.

Functions§

connect
Connect to the given URL, and return a sender and receiver.
connect_with_wakeup
Like connect, but will call the given wake-up function on each incoming event.
ws_connect
Connect and call the given event handler on each received event.
ws_receive
Connect and call the given event handler on each received event.

Type Aliases§

Error
An error.
Result
Short for Result<T, ewebsock::Error>.