Skip to main content

ntex/ws/
mod.rs

1//! WebSocket protocol support.
2//!
3//! Use [`handshake()`] or [`handshake_response()`] to perform a server-side
4//! opening handshake, and [`WsClient`] to establish a client connection.
5//!
6//! Framed communication uses [`Codec`] to encode and decode [`Frame`]s and
7//! [`Message`]s. On the client side, [`WsConnection::start()`] runs a frame
8//! handling service, [`WsConnection::receiver()`] returns a stream of frames,
9//! and [`WsConnection::sink()`] returns a [`WsSink`] for sending messages.
10//!
11//! [`WsTransport`] is a byte-stream filter instead: binary and continuation
12//! frames are exposed as raw bytes, text frames are rejected, and control
13//! frames are handled internally. Use [`WsConnection::into_transport()`] to
14//! run a byte-oriented protocol over a WebSocket connection.
15//!
16//! With the `compress` feature, the client can negotiate the
17//! `permessage-deflate` extension (RFC 7692), see
18//! [`WsClientConfig::set_deflate()`]. The server accepts it with
19//! [`DeflateConfig::negotiate()`], or with
20//! [`HttpServiceConfig::set_ws_deflate()`](crate::http::HttpServiceConfig::set_ws_deflate)
21//! for [`web::ws::start()`](crate::web::ws::start).
22mod cfg;
23mod client;
24mod codec;
25#[cfg(feature = "compress")]
26mod deflate;
27mod frame;
28mod handshake;
29mod mask;
30mod proto;
31mod sink;
32mod transport;
33
34pub mod error;
35
36pub use self::cfg::WsClientConfig;
37pub use self::client::{WsClient, WsConnection};
38pub use self::codec::{Codec, Frame, Item, Message};
39#[cfg(feature = "compress")]
40pub use self::deflate::DeflateConfig;
41pub use self::frame::Parser;
42pub use self::handshake::{handshake, handshake_response, verify_handshake};
43pub use self::proto::{CloseCode, CloseReason, OpCode, hash_key};
44pub use self::sink::WsSink;
45pub use self::transport::{WsTransport, WsTransportService};
46
47pub(crate) use self::cfg::is_token;