Module awc::ws[][src]

Expand description

Websockets client

Type definitions required to use awc::Client as a WebSocket client.

Example

use awc::{Client, ws};
use futures_util::{sink::SinkExt as _, stream::StreamExt as _};

#[actix_rt::main]
async fn main() {
    let (_resp, mut connection) = Client::new()
        .ws("ws://echo.websocket.org")
        .connect()
        .await
        .unwrap();

    connection
        .send(ws::Message::Text("Echo".into()))
        .await
        .unwrap();
    let response = connection.next().await.unwrap().unwrap();

    assert_eq!(response, ws::Frame::Text("Echo".as_bytes().into()));
}

Structs

CloseReason

Reason for closing the connection

Codec

WebSocket protocol codec.

WebsocketsRequest

WebSocket connection.

Enums

CloseCode

Status code used to indicate why an endpoint is closing the WebSocket connection.

Frame

A WebSocket frame.

Message

A WebSocket message.