Skip to main content

WebSocketTransport

Struct WebSocketTransport 

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

A Transport backed by a tokio-tungstenite WebSocket stream.

Use WebSocketTransport::connect for the common case, or WebSocketTransport::from_stream when you need custom connection options (custom TLS configuration, additional headers, etc.).

§Example

use ahp::{Client, ClientConfig};
use ahp_ws::WebSocketTransport;

let transport = WebSocketTransport::connect("ws://localhost:12345").await?;
let client = Client::connect(transport, ClientConfig::default()).await?;
client.initialize("demo".into(), vec!["0.1.0".into()], vec![]).await?;

Implementations§

Source§

impl WebSocketTransport

Source

pub async fn connect(url: &str) -> Result<Self, WebSocketTransportError>

Open a new WebSocket connection to url.

Both ws:// and wss:// schemes are accepted; the wss:// TLS backend is chosen at compile time by Cargo feature (see the crate docs), defaulting to rustls with OS-trust-store roots. The URL is parsed eagerly so malformed URLs surface as WebSocketTransportError::InvalidUrl before any network I/O.

Source

pub fn from_stream(inner: WebSocketStream<MaybeTlsStream<TcpStream>>) -> Self

Wrap an already-connected WebSocket stream.

Use this when you need to drive the tokio-tungstenite handshake yourself — for custom TLS configuration, request headers, or to reuse an existing socket.

Trait Implementations§

Source§

impl Transport for WebSocketTransport

Source§

async fn send(&mut self, msg: TransportMessage) -> Result<(), TransportError>

Send a single message. Read more
Source§

async fn recv(&mut self) -> Result<Option<TransportMessage>, TransportError>

Receive the next inbound message. Read more
Source§

async fn close(&mut self) -> Result<(), TransportError>

Close the transport and release any underlying resources. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> DynTransport for T
where T: Transport,

Source§

fn send<'a>( &'a mut self, msg: TransportMessage, ) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'a>>

Object-safe analogue of Transport::send.
Source§

fn recv<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = Result<Option<TransportMessage>, TransportError>> + Send + 'a>>

Object-safe analogue of Transport::recv.
Source§

fn close<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'a>>

Object-safe analogue of Transport::close.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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