### Add impcurl-ws to Cargo.toml Source: https://github.com/tuchg/impcurl/blob/main/README.md Include impcurl-ws and its dependencies in your Cargo.toml file to start using the library. ```toml [dependencies] impcurl-ws = "1.1.1" utures-util = "0.3" tokio = { version = "1", features = ["macros", "rt-multi-thread"] } ``` -------------------------------- ### Basic Async WebSocket Connection and Message Handling Source: https://github.com/tuchg/impcurl/blob/main/README.md Connect to a WebSocket server, send a text message, and receive a response. Handles basic text and binary message types. ```rust use futures_util::{SinkExt, StreamExt}; use impcurl_ws::{Message, WsConnection}; #[tokio::main] async fn main() -> anyhow::Result<()> { let mut ws = WsConnection::connect("wss://echo.websocket.org").await?; ws.send(Message::Text("hello".to_owned())).await?; if let Some(message) = ws.next().await.transpose()? { match message { Message::Text(text) => println("{text}"), Message::Binary(bytes) => println!("{bytes} bytes"), Message::Ping(_) | Message::Pong(_) | Message::Close(_) => {} } } Ok(()) } ``` -------------------------------- ### Advanced WebSocket Connection with Builder API Source: https://github.com/tuchg/impcurl/blob/main/README.md Configure a WebSocket connection using the builder pattern, setting custom headers, proxy, impersonation target, timeouts, and buffer sizes. ```rust use impcurl::ImpersonateTarget; use impcurl_ws::{ControlFrameMode, WsConnection}; use std::time::Duration; let ws = WsConnection::builder("wss://example.com/ws") .header("Origin", "https://example.com") .header("User-Agent", "Mozilla/5.0 ...") .proxy("socks5h://127.0.0.1:1080") .impersonate(ImpersonateTarget::Chrome136) .connect_timeout(Duration::from_secs(10)) .control_frame_mode(ControlFrameMode::Manual) .read_buffer_messages(32) .write_buffer_messages(32) .verbose(true) .connect() .await?; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.