Connect A Listener To A Websocket Server In Rust With tokio-tungstenite
This is a cut down version of the client example from the tokio-tungstenite create. It connects to a websocket server and prints any messages it receives to the console.
Code
#!/usr/bin/env cargo +nightly -Zscript
//! ```cargo
//! [dependencies]
//! futures-util = { version = "0.3.28" }
//! tokio = { version = "1.0.0", features = ["full"] }
//! tokio-tungstenite = "*"
//! url = "2.4.1"
//! ```
use StreamExt;
use AsyncWriteExt;
use connect_async;
async
Notes
The original example read stdin and sent whatever it received to the server. There was a bunch of extra futures stuff invovled in that. I ripped all that out since I just want a listener client
I'm still new to async/tokio/futures. This code is working in issolation. I don't know if it would need to be tweaked to work in more complicated coded bases
References
-
The base I whittled down to get the example above