Skip to main content

Module ws

Module ws 

Source
Expand description

Websockets client

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

§Examples

use awc::{Client, ws};
use futures_util::{SinkExt as _, 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.