pub struct Client<S> { /* private fields */ }Expand description
WebSocket stream — owns a socket, reader, writer, and buffers.
Handles both plain ws:// and encrypted wss:// connections.
The URL scheme determines whether TLS is used — no separate type needed.
§Usage
use nexus_web::ws::Client;
use nexus_web::tls::TlsConfig;
// Plain WebSocket
let mut ws = Client::builder().connect("ws://localhost:8080/ws")?;
// TLS WebSocket (requires 'tls' feature)
let tls = TlsConfig::new()?;
let mut ws = Client::builder().tls(&tls).connect("wss://exchange.com/ws")?;
// Same API for both:
ws.send_text("Hello!")?;
while let Some(msg) = ws.recv()? {
// ...
}Implementations§
Source§impl Client<TcpStream>
impl Client<TcpStream>
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Create a builder for configuring buffer sizes, socket options, and TLS.
Source§impl<S> Client<S>
impl<S> Client<S>
Sourcepub fn from_parts(stream: S, reader: FrameReader, writer: FrameWriter) -> Self
pub fn from_parts(stream: S, reader: FrameReader, writer: FrameWriter) -> Self
Create from pre-existing parts. For testing or custom handshakes.
Sourcepub fn is_poisoned(&self) -> bool
pub fn is_poisoned(&self) -> bool
Whether the stream is poisoned (I/O error occurred during send).
A poisoned stream should not be reused — the connection may be in an indeterminate state (partial frame written).
Sourcepub fn stream_mut(&mut self) -> &mut S
pub fn stream_mut(&mut self) -> &mut S
Mutable access to the underlying stream.
Sourcepub fn reader(&self) -> &FrameReader
pub fn reader(&self) -> &FrameReader
Access the FrameReader.
Sourcepub fn frame_writer(&self) -> &FrameWriter
pub fn frame_writer(&self) -> &FrameWriter
Access the FrameWriter.
Source§impl<S: Read + Write> Client<S>
impl<S: Read + Write> Client<S>
Sourcepub fn connect_with(stream: S, url: &str) -> Result<Self, Error>
pub fn connect_with(stream: S, url: &str) -> Result<Self, Error>
Connect using a pre-connected socket with default configuration.
IPv6 addresses must use bracket notation: ws://[::1]:8080/path.
Sourcepub fn accept(stream: S) -> Result<Self, Error>
pub fn accept(stream: S) -> Result<Self, Error>
Accept an incoming WebSocket connection (server-side).