Skip to content

Commit

Permalink
Add an example (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-zero authored Dec 29, 2021
1 parent 0263f0e commit c7b8cd3
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//! A mDNS query client.
//!
//! Run with:
//!
//! cargo run --example query <service_type>
//!
//! Keeps listening for new events.
use mdns_sd::{ServiceDaemon, ServiceEvent};

fn main() {
// Create a daemon
let mdns = ServiceDaemon::new().expect("Failed to create daemon");

let mut service_type = std::env::args()
.nth(1)
.expect("it requires a service_type as argument");

// Browse for a service type.
service_type.push_str(".local.");
let receiver = mdns.browse(&service_type).expect("Failed to browse");

while let Ok(event) = receiver.recv() {
match event {
ServiceEvent::ServiceResolved(info) => {
println!("Resolved a new service: {}", info.get_fullname());
}
other_event => {
println!("Received other event: {:?}", &other_event);
}
}
}
}

0 comments on commit c7b8cd3

Please sign in to comment.