Module websocket::client::async [−][src]
Contains the asynchronous websocket client.
The async client is simply a Stream + Sink
of OwnedMessage
structs.
This definition means that you don’t have to learn any new APIs other than
futures-rs.
The client simply wraps around an AsyncRead + AsyncWrite
stream and uses
a MessageCodec
to chop up the bytes into websocket messages.
See the codec
module for all the cool codecs this crate has.
Since this is all asynchronous, you will not create a client from ClientBuilder
but instead you will create a ClientNew
struct, which is a Future that
will eventually evaluate to a Client
.
Example with Type Annotations
use websocket::ClientBuilder; use websocket::async::client::{Client, ClientNew}; use websocket::async::TcpStream; use websocket::futures::{Future, Stream, Sink}; use websocket::Message; use tokio::runtime::Builder; let mut runtime = Builder::new().build().unwrap(); // create a Future of a client let client_future: ClientNew<TcpStream> = ClientBuilder::new("ws://echo.websocket.org").unwrap() .async_connect_insecure(); // send a message let send_future = client_future .and_then(|(client, headers)| { // just to make it clear what type this is let client: Client<TcpStream> = client; client.send(Message::text("hallo").into()) }); runtime.block_on(send_future).unwrap();
Structs
Framed | A unified |
Handle | A reference to a reactor. |
TcpStream | An I/O object representing a TCP stream connected to a remote endpoint. |
TlsStream | A wrapper around an underlying raw stream which implements the TLS or SSL protocol. |
Traits
Future | Trait for types which are a placeholder of a value that may become available at some later point in time. |
Type Definitions
Client | An asynchronous websocket client. |
ClientNew | A future which will evaluate to a |