Last active
September 11, 2015 19:16
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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