Crates.io | tungstenite-get-stream |
lib.rs | tungstenite-get-stream |
version | 0.1.0 |
created_at | 2025-06-22 04:11:05.275959+00 |
updated_at | 2025-06-22 04:11:05.275959+00 |
description | Convenience trait method to get underlying stream |
homepage | |
repository | https://gitlab.com/spearman/tungstenite-get-stream |
max_upload_size | |
id | 1721268 |
size | 24,833 |
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}")
}
}
}