Module awc::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§

Enums§

  • Status code used to indicate why an endpoint is closing the WebSocket connection.
  • A WebSocket frame.
  • A WebSocket message.