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>
impl WsClient<Base>
Sourcepub fn new<U>(uri: U, cfg: impl Into<Cfg<WsClientConfig>>) -> Self
pub fn new<U>(uri: U, cfg: impl Into<Cfg<WsClientConfig>>) -> Self
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>
impl<F> WsClient<F>
Sourcepub fn connector<U, S>(
self,
f: impl IntoService<S, SharedCfg, Connect<Url>>,
) -> WsClient<U>
pub fn connector<U, S>( self, f: impl IntoService<S, SharedCfg, Connect<Url>>, ) -> WsClient<U>
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§impl<F> WsClient<F>where
F: Filter,
impl<F> WsClient<F>where
F: Filter,
Sourcepub async fn connect(&self) -> Result<WsConnection<F>, Error<WsClientError>>
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.