Skip to content

Commit

Permalink
example code: refactor the query output prints and the register hostn…
Browse files Browse the repository at this point in the history
…ame (#189)

* improve the format of query output
* define the service hostname based on instance and service type
  • Loading branch information
keepsimple1 authored Mar 26, 2024
1 parent dcf0744 commit c141cb3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions examples/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ fn main() {
match event {
ServiceEvent::ServiceResolved(info) => {
println!(
"At {:?}: Resolved a new service: {} host: {} port: {} IP: {:?} TXT properties: {:?}",
"At {:?}: Resolved a new service: {}\n host: {}\n port: {}",
now.elapsed(),
info.get_fullname(),
info.get_hostname(),
info.get_port(),
info.get_addresses(),
info.get_properties(),
);
for addr in info.get_addresses().iter() {
println!(" Address: {}", addr);
}
for prop in info.get_properties().iter() {
println!(" Property: {}", prop);
}
}
other_event => {
println!("At {:?} : {:?}", now.elapsed(), &other_event);
Expand Down
4 changes: 2 additions & 2 deletions examples/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn main() {
// With `enable_addr_auto()`, we can give empty addrs and let the lib find them.
// If the caller knows specific addrs to use, then assign the addrs here.
let my_addrs = "";
let service_hostname = "mdns-example.local.";
let service_hostname = format!("{}{}", instance_name, &service_type);
let port = 3456;

// The key string in TXT properties is case insensitive. Only the first
Expand All @@ -55,7 +55,7 @@ fn main() {
let service_info = ServiceInfo::new(
&service_type,
instance_name,
service_hostname,
&service_hostname,
my_addrs,
port,
&properties[..],
Expand Down

0 comments on commit c141cb3

Please sign in to comment.