Skip to content

Instantly share code, notes, and snippets.

@makuk66
Last active September 11, 2015 19:16
Show Gist options
  • Save makuk66/37c2d67a3ad8c5a9ab6b to your computer and use it in GitHub Desktop.
Save makuk66/37c2d67a3ad8c5a9ab6b to your computer and use it in GitHub Desktop.
zookeeper "ruok" client, which properly reports errors, including the server address on connect.
use std::io::prelude::*;
use std::net::TcpStream;
fn main() {
let address = "192.168.0.109:9983";
let mut stream = match TcpStream::connect(address) {
Ok(s) => s,
Err(e) => panic!("Cannot connect to {}: {}", address, e)
};
stream.write("ruok".as_bytes()).ok().expect("write failed");
let mut buf = String::new();
stream.read_to_string(&mut buf).ok().expect("read failed");
println!("{}", buf);
}
@makuk66
Copy link
Author

makuk66 commented Sep 11, 2015

This can hang up to a minute if the target is unreachable.
See http://stackoverflow.com/questions/30022084/how-do-i-set-connect-timeout-on-tcpstream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment