tungstenite-get-stream
Convenience trait method to match on a tungstenite::MaybeTlsStream<S> and get
the underlying stream (usually std::net::TcpStream).
Note that native-tls or rustls-tls method must be enabled on this crate to
access a TLS-enabled stream otherwise the methods will panic.
use tungstenite;
use tungstenite_get_stream::GetStream;
fn main() {
let (mut ws, _resp) = tungstenite::connect("ws://foo.com:12345").unwrap();
ws.get_stream().set_nonblocking(true).unwrap();
loop {
match ws.read() {
Ok (msg) => println!("MSG: {msg:?}"),
Err (tungstenite::Error::Io(err))
if err.kind() == std::io::ErrorKind::WouldBlock => {
println!("TICK");
std::thread::sleep(std::time::Duration::from_secs (2));
}
Err(e) => panic!("read error: {e}")
}
}
}