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.
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.
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.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more