Struct tokio_websockets::client::Builder

source ·
pub struct Builder<'a, R: Resolver = Gai> { /* private fields */ }
Available on crate feature client only.
Expand description

Builder for WebSocket client connections.

Implementations§

source§

impl<'a> Builder<'a>

source

pub fn new() -> Self

Creates a Builder with all defaults that is not configured to connect to any server.

source

pub fn from_uri(uri: Uri) -> Self

Creates a Builder that connects to a given URI. This URI must use the ws or wss schemes.

This method never fails as the URI has already been parsed.

source§

impl<'a, R: Resolver> Builder<'a, R>

source

pub fn uri(self, uri: &str) -> Result<Self, InvalidUri>

Sets the Uri to connect to. This URI must use the ws or wss schemes.

§Errors

This method returns a http::uri::InvalidUri error if URI parsing fails.

source

pub fn connector(self, connector: &'a Connector) -> Self

Sets the TLS connector for the client.

By default, the client will create a new one for each connection instead of reusing one.

source

pub fn resolver<NewR: Resolver>(self, resolver: NewR) -> Builder<'a, NewR>

Sets the DNS resolver for the client.

By default, the client will use the Gai resolver, a wrapper around the blocking getaddrinfo syscall.

source

pub fn config(self, config: Config) -> Self

Sets the configuration for the WebSocket stream.

source

pub fn limits(self, limits: Limits) -> Self

Sets the limits for the WebSocket stream.

source

pub fn add_header(self, name: HeaderName, value: HeaderValue) -> Self

Adds an extra HTTP header to the handshake request.

source

pub async fn connect( &self ) -> Result<(WebSocketStream<MaybeTlsStream<TcpStream>>, Response), Error>

Establishes a connection to the WebSocket server. This requires a URI to be configured via Builder::uri.

§Errors

This method returns an Error if connecting to the server fails or no URI has been configured.

source

pub async fn connect_on<S: AsyncRead + AsyncWrite + Unpin>( &self, stream: S ) -> Result<(WebSocketStream<S>, Response), Error>

Takes over an already established stream and uses it to send and receive WebSocket messages. This requires a URI to be configured via Builder::uri.

This method assumes that the TLS connection has already been established, if needed. It sends an HTTP upgrade request and waits for an HTTP Switching Protocols response before proceeding.

§Errors

This method returns an Error if writing or reading from the stream fails or no URI has been configured.

source

pub fn take_over<S: AsyncRead + AsyncWrite + Unpin>( &self, stream: S ) -> WebSocketStream<S>

Takes over an already established stream that has already performed a HTTP upgrade handshake and uses it to send and receive WebSocket messages.

This method will not perform a TLS handshake or a HTTP upgrade handshake, it assumes the stream is ready to use for writing and reading the WebSocket protocol.

Trait Implementations§

source§

impl<'a> Default for Builder<'a>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a, R = Gai> !Freeze for Builder<'a, R>

§

impl<'a, R = Gai> !RefUnwindSafe for Builder<'a, R>

§

impl<'a, R> Send for Builder<'a, R>

§

impl<'a, R> Sync for Builder<'a, R>
where R: Sync,

§

impl<'a, R> Unpin for Builder<'a, R>
where R: Unpin,

§

impl<'a, R = Gai> !UnwindSafe for Builder<'a, R>

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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