pub struct WsTransport { /* private fields */ }
Expand description

A WebSocket-based Transport.

Supports endpoints of the format ws://ip_or_host:port.

Examples

To connect to the a remote endpoint, send a message, and receive a reply message:

use splinter::transport::Transport as _;
use splinter::transport::ws::WsTransport;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut transport = WsTransport::new(None)?;

    // Connect to a remote endpoint starting wtih `ws://`.
    let mut connection = transport.connect("ws://127.0.0.1:5555")?;

    // Send some bytes
    connection.send(b"hello world")?;

    // Receive a response
    let msg = connection.recv()?;

    // Disconnect
    connection.disconnect()?;

    Ok(())
}

To accept a connection, receive, and send a reply:

use splinter::transport::Transport as _;
use splinter::transport::ws::WsTransport;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut transport = WsTransport::new(None)?;

    // Create a listener, which will bind to the port
    let mut listener = transport.listen("ws://127.0.0.1:5555")?;

    // When the other side connects, accept will return a `Connection`
    let mut connection = listener.accept()?;

    // Receive a message
    let msg = connection.recv()?;

    // Send a response
    connection.send(b"hello world")?;

    // Disconnect
    connection.disconnect()?;

    Ok(())
}

Implementations

Trait Implementations

Returns the “default value” for a type. Read more

Indicates whether or not a given address can be used to create a connection or listener.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Convert self to an expression for Diesel’s query builder. Read more

Convert &self to an expression for Diesel’s query builder. Read more

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more