tungstenite-get-stream

Crates.iotungstenite-get-stream
lib.rstungstenite-get-stream
version0.1.0
created_at2025-06-22 04:11:05.275959+00
updated_at2025-06-22 04:11:05.275959+00
descriptionConvenience trait method to get underlying stream
homepage
repositoryhttps://gitlab.com/spearman/tungstenite-get-stream
max_upload_size
id1721268
size24,833
Shane Pearman (spearman)

documentation

README

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}")
    }
  }
}
Commit count: 0

cargo fmt