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.

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.

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> !Freeze for WsClient<F>

§

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

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.