https://docs.rs/websockets/latest/websockets/struct.WebSocket.html
websockets=”0.3.0″
use websockets::WebSocket;
use websockets::Frame;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut ws = WebSocket::connect("wss://echo.websocket.org/").await?;
ws.send_text("foo".to_string()).await?;
ws.receive().await?;
if let Frame::Text { payload: received_msg, .. } = ws.receive().await? {
println!("{}", received_msg);
}
ws.close(None).await?;
Ok(())
}
Compiling app v0.1.0 (/home/vagrant/dev/rust/app)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.00s
Running `target/debug/app`
foo
なるほどー