Skip to main content

WsClient

Struct WsClient 

Source
pub struct WsClient<F> { /* private fields */ }
Expand description

Builder for establishing a WebSocket client connection.

The builder contains the target URI and a typed WsClientConfig. Use connect to perform the opening handshake.

Implementations§

Source§

impl WsClient<Base>

Source

pub fn new<U>(uri: U, cfg: impl Into<Cfg<WsClientConfig>>) -> Self
where Url: TryFrom<U>, WsConfigError: From<<Url as TryFrom<U>>::Error>,

Creates a client for uri using the supplied configuration.

use ntex::{SharedCfg, time::Seconds};
use ntex::ws::{WsClient, WsClientConfig};

#[ntex::main]
async fn main() {
    let cfg = SharedCfg::new("WS-CLIENT").add(
        WsClientConfig::new()
            .set_max_frame_size(128 * 1024)
            .set_handshake_timeout(Seconds(10))
    );

    let _client = WsClient::new("ws://localhost/socket", cfg);
}

URI conversion and validation errors are stored and returned by connect.

The default connector is plain TCP, so wss and https URIs fail with WsConfigError::TlsRequired unless a TLS connector is installed with openssl(), rustls() or connector.

Source§

impl<F> WsClient<F>

Source

pub fn connector<U, S>( self, f: impl IntoService<S, SharedCfg, Connect<Url>>, ) -> WsClient<U>
where U: Filter + 'static, S: Service<SharedCfg, Connect<Url>, Res = Io<U>, Error = Error<ConnectError>> + 'static,

Replaces the network connector used to establish the connection.

The connector is used for every scheme; it is responsible for applying TLS to wss and https URIs.

Source

pub fn openssl(self, config: SslConnector) -> WsClient<Layer<SslFilter>>

Uses the supplied OpenSSL connector for secure connections.

Source

pub fn rustls( self, config: Arc<RustlsClientConfig>, ) -> WsClient<Layer<TlsClientFilter>>

Uses the supplied rustls connector for secure connections.

Source§

impl<F> WsClient<F>
where F: Filter,

Source

pub async fn connect(&self) -> Result<WsConnection<F>, Error<WsClientError>>

Establishes the connection and performs the WebSocket opening handshake.

§Errors

Returns an error if connection establishment, HTTP encoding or decoding, URI validation, timeout handling, or handshake validation fails.

Trait Implementations§

Source§

impl<F> Debug for WsClient<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<F> !RefUnwindSafe for WsClient<F>

§

impl<F> !Send for WsClient<F>

§

impl<F> !Sync for WsClient<F>

§

impl<F> !UnwindSafe for WsClient<F>

§

impl<F> Freeze for WsClient<F>

§

impl<F> Unpin for WsClient<F>
where F: Unpin,

§

impl<F> UnsafeUnpin for WsClient<F>

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
§

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

§

fn vzip(self) -> V