housleyjk / ws-rs

Lightweight, event-driven WebSockets for Rust.
MIT License
1.46k stars 219 forks source link

how to set header,thanks #333

Open bhltyou opened 3 years ago

bhltyou commented 3 years ago
if let Err(error) = connect("ws://echo.websocket.org", |out| {
    // Queue a message to be sent when the WebSocket is open
    if out.send("Hello WebSocket").is_err() {
        println!("Websocket couldn't queue an initial message.")
    } else {
        println!("Client sent message 'Hello WebSocket'. ")
    }

    // The handler needs to take ownership of out, so we use move
    move |msg| {
        // Handle messages received on this connection
        println!("Client got message '{}'. ", msg);

        // Close the connection
        out.close(CloseCode::Normal)
    }
}) {
    // Inform the user of failure
    println!("Failed to create WebSocket due to: {:?}", error);
}