Expand description
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::r#async::client::{Client, ClientNew};
use websocket::r#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
A unified Stream
and Sink
interface to an underlying I/O object, using
the Encoder
and Decoder
traits to encode and decode frames.
A reference to a reactor.
An I/O object representing a TCP stream connected to a remote endpoint.
A wrapper around an underlying raw stream which implements the TLS or SSL protocol.
Traits
Trait for types which are a placeholder of a value that may become available at some later point in time.