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);
}