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

High level management interface for WebSocket transports.

Be aware that only one WebSocketTransport can exist per node, as it registers itself as a router for the WS address type. Multiple calls to WebSocketTransport::create will fail.

To listen for incoming connections use ws.listen().

To register additional connections on an already initialised WebSocketTransport, use ws.connect(). This step is optional because the underlying WebSocketRouter is capable of lazily establishing a connection upon arrival of an initial message.

use ockam_transport_websocket::WebSocketTransport;
let ws = WebSocketTransport::create(&ctx).await?;
ws.listen("127.0.0.1:8000").await?; // Listen on port 8000
ws.connect("127.0.0.1:5000").await?; // And connect to port 5000

The same WebSocketTransport can also bind to multiple ports.

use ockam_transport_websocket::WebSocketTransport;
let ws = WebSocketTransport::create(&ctx).await?;
ws.listen("127.0.0.1:8000").await?; // Listen on port 8000
ws.listen("127.0.0.1:9000").await?; // Listen on port 9000

Implementations

Create a new WebSocket transport and router for the current node.

use ockam_transport_websocket::WebSocketTransport;
let ws = WebSocketTransport::create(&ctx).await?;

Establish an outgoing WebSocket connection on an existing transport.

use ockam_transport_websocket::WebSocketTransport;
let ws = WebSocketTransport::create(&ctx).await?;
ws.listen("127.0.0.1:8000").await?; // Listen on port 8000
ws.connect("127.0.0.1:5000").await?; // and connect to port 5000

Start listening to incoming connections on an existing transport.

Returns the local address that this transport is bound to.

This can be useful, for example, when binding to port 0 to figure out which port was actually bound.

use ockam_transport_websocket::WebSocketTransport;
let ws = WebSocketTransport::create(&ctx).await?;
ws.listen("127.0.0.1:8000").await?;

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

Calls U::from(self).

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

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