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
impl WebSocketTransport
Sourcepub async fn connect(url: &str) -> Result<Self, WebSocketTransportError>
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.
Sourcepub fn from_stream(inner: WebSocketStream<MaybeTlsStream<TcpStream>>) -> Self
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
impl Transport for WebSocketTransport
Source§async fn send(&mut self, msg: TransportMessage) -> Result<(), TransportError>
async fn send(&mut self, msg: TransportMessage) -> Result<(), TransportError>
Source§async fn recv(&mut self) -> Result<Option<TransportMessage>, TransportError>
async fn recv(&mut self) -> Result<Option<TransportMessage>, TransportError>
Auto Trait Implementations§
impl !Freeze for WebSocketTransport
impl !RefUnwindSafe for WebSocketTransport
impl !UnwindSafe for WebSocketTransport
impl Send for WebSocketTransport
impl Sync for WebSocketTransport
impl Unpin for WebSocketTransport
impl UnsafeUnpin for WebSocketTransport
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> DynTransport for Twhere
T: Transport,
impl<T> DynTransport for Twhere
T: Transport,
Source§fn send<'a>(
&'a mut self,
msg: TransportMessage,
) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'a>>
fn send<'a>( &'a mut self, msg: TransportMessage, ) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'a>>
Transport::send.Source§fn recv<'a>(
&'a mut self,
) -> Pin<Box<dyn Future<Output = Result<Option<TransportMessage>, TransportError>> + Send + 'a>>
fn recv<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = Result<Option<TransportMessage>, TransportError>> + Send + 'a>>
Transport::recv.