| 1 | use pinger::{ping, PingOptions}; |
| 2 | |
| 3 | const LIMIT: usize = 3; |
| 4 | |
| 5 | pub fn main() { |
| 6 | let target = "tomforb.es".to_string(); |
| 7 | let interval = std::time::Duration::from_millis(500); |
| 8 | let options = PingOptions::new(target, interval, None); |
| 9 | let stream = ping(options).expect("Error pinging"); |
| 10 | for message in stream.into_iter().take(LIMIT) { |
| 11 | match message { |
| 12 | pinger::PingResult::Pong(duration, line) => { |
| 13 | println!("Duration: {:?}\t\t(raw: {:?})", duration, line) |
| 14 | } |
| 15 | pinger::PingResult::Timeout(line) => println!("Timeout! (raw: {line:?})"), |
| 16 | pinger::PingResult::Unknown(line) => println!("Unknown line: {:?}", line), |
| 17 | pinger::PingResult::PingExited(code, stderr) => { |
| 18 | panic!("Ping exited! Code: {:?}. Stderr: {:?}", code, stderr) |
| 19 | } |
| 20 | } |
| 21 | } |
| 22 | } |