tungstenite-get-stream 0.1.0

Convenience trait method to get underlying stream
Documentation
  • Coverage
  • 25%
    1 out of 4 items documented0 out of 3 items with examples
  • Size
  • Source code size: 24.83 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 336.54 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 19s Average build duration of successful builds.
  • all releases: 19s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • spearman

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