Crate async_tungstenite

Crate async_tungstenite 

Source
Expand description

Async WebSockets.

This crate is based on tungstenite Rust WebSocket library and provides async bindings and wrappers for it, so you can use it with non-blocking/asynchronous TcpStreams from and couple it together with other crates from the async stack. In addition, optional integration with various other crates can be enabled via feature flags

  • async-tls: Enables the async_tls module, which provides integration with the async-tls TLS stack and can be used independent of any async runtime.
  • async-std-runtime: Enables the async_std module, which provides integration with the async-std runtime.
  • async-native-tls: Enables the additional functions in the async_std module to implement TLS via async-native-tls.
  • tokio-runtime: Enables the tokio module, which provides integration with the tokio runtime.
  • tokio-native-tls: Enables the additional functions in the tokio module to implement TLS via tokio-native-tls.
  • tokio-rustls-native-certs: Enables the additional functions in the tokio module to implement TLS via tokio-rustls and uses native system certificates found with rustls-native-certs.
  • tokio-rustls-webpki-roots: Enables the additional functions in the tokio module to implement TLS via tokio-rustls and uses the certificates webpki-roots provides.
  • tokio-openssl: Enables the additional functions in the tokio module to implement TLS via tokio-openssl.
  • gio-runtime: Enables the gio module, which provides integration with the gio runtime.

Each WebSocket stream implements the required Stream and Sink traits, making the socket a stream of WebSocket messages coming in and going out.

Re-exportsยง

pub use bytes::ByteReader;
pub use bytes::ByteWriter;
pub use tungstenite;

Modulesยง

bytes
Provides abstractions to use AsyncRead and AsyncWrite with a WebSocketStream or a WebSocketSender.
compat ๐Ÿ”’
handshake ๐Ÿ”’
stream
Convenience wrapper for streams to switch between plain TCP and TLS at runtime.
tokio
tokio integration.

Structsยง

Send ๐Ÿ”’
Shared ๐Ÿ”’
WebSocketReceiver
The receiver part of a websocket stream.
WebSocketSender
The sender part of a websocket stream.
WebSocketStream
A wrapper around an underlying raw stream which implements the WebSocket protocol.

Functionsยง

accept_async
Accepts a new WebSocket connection with the provided stream.
accept_async_with_config
The same as accept_async() but the one can specify a websocket configuration. Please refer to accept_async() for more details.
accept_hdr_async
Accepts a new WebSocket connection with the provided stream.
accept_hdr_async_with_config
The same as accept_hdr_async() but the one can specify a websocket configuration. Please refer to accept_hdr_async() for more details.
client_async
Creates a WebSocket handshake from a request and a stream. For convenience, the user may call this with a url string, a URL, or a Request. Calling with Request allows the user to add a WebSocket protocol or other custom headers.
client_async_with_config
The same as client_async() but the one can specify a websocket configuration. Please refer to client_async() for more details.
domain ๐Ÿ”’
Get a domain from an URL.
port ๐Ÿ”’
Get the port from an URL.
send_helper ๐Ÿ”’
Performs an asynchronous message send to the websocket.