Skip to main content

ClientBuilder

Struct ClientBuilder 

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

Builder for Client.

Configures buffer sizes, socket options, and optional TLS.

§Examples

let mut ws = Client::builder()
    .disable_nagle()
    .buffer_capacity(2 * 1024 * 1024)
    .connect("wss://exchange.com/ws")?;

Implementations§

Source§

impl ClientBuilder

Source

pub fn begin_connect<S: Read + Write>( self, stream: S, url: &str, ) -> Result<Connecting<S>, Error>

Start a non-blocking connection handshake.

Returns a Connecting that must be driven to completion via poll() before messages can be sent/received.

The caller is responsible for setting the socket to non-blocking mode before calling this.

Source§

impl ClientBuilder

Source

pub fn new() -> Self

Create a new builder with defaults.

Source

pub fn buffer_capacity(self, n: usize) -> Self

ReadBuf capacity. Default: 1MB.

Source

pub fn max_frame_size(self, n: u64) -> Self

Maximum single frame payload. Default: 16MB.

Source

pub fn max_message_size(self, n: usize) -> Self

Maximum assembled message size. Default: 16MB.

Source

pub fn write_buffer_capacity(self, n: usize) -> Self

Write buffer capacity. Default: 64KB.

Source

pub fn disable_nagle(self) -> Self

Set TCP_NODELAY (disable Nagle’s algorithm).

Source

pub fn recv_buffer_size(self, n: usize) -> Self

Set SO_RCVBUF (socket receive buffer size).

Source

pub fn send_buffer_size(self, n: usize) -> Self

Set SO_SNDBUF (socket send buffer size).

Source

pub fn connect_timeout(self, d: Duration) -> Self

TCP connect timeout.

Source

pub fn read_timeout(self, d: Duration) -> Self

Socket read timeout.

Source

pub fn tls(self, config: &TlsConfig) -> Self

Set a custom TLS configuration.

If not set, wss:// URLs use TlsConfig::new() (system defaults).

Source

pub fn connect(self, url: &str) -> Result<Client<MaybeTls<TcpStream>>, Error>

Connect to a WebSocket server (blocking).

Creates a TCP socket, applies socket options, and performs the full handshake (TLS if wss://, then HTTP upgrade).

When the tls feature is enabled, returns Client<MaybeTls<TcpStream>> regardless of scheme — ws:// uses MaybeTls::Plain, wss:// uses MaybeTls::Tls. Without the tls feature, returns Client<TcpStream> and errors on wss://.

Source

pub fn connect_with<S: Read + Write>( self, stream: S, url: &str, ) -> Result<Client<S>, Error>

Connect using a pre-connected stream.

The stream must already handle TLS if connecting to wss://. For example, pass a TlsStream<TcpStream> or MaybeTls<TcpStream>. This method only performs the HTTP upgrade handshake.

Source

pub fn accept<S: Read + Write>(self, stream: S) -> Result<Client<S>, Error>

Accept an incoming WebSocket connection (server-side).

Trait Implementations§

Source§

impl Default for ClientBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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