Struct simple_mdns::ServiceDiscovery [−][src]
pub struct ServiceDiscovery { /* fields omitted */ }Expand description
Service Discovery implementation using DNS-SD. This implementation advertise all the registered addresses, query for the same service on the same network and keeps a cache of known service instances
Notice that this crate does not provide any means of finding your own ip address. There are crates that provide this kind of feature.
Example
use simple_mdns::ServiceDiscovery; use std::net::SocketAddr; let mut discovery = ServiceDiscovery::new("_mysrv._tcp.local", 60).expect("Invalid Service Name"); let my_socket_addr = "192.168.1.22:8090".parse().unwrap(); discovery.add_socket_address(my_socket_addr);
Implementations
Creates a new ServiceDiscovery by providing service_name, resource ttl and loopback activation.
service_name must be in the standard specified by the mdns RFC, example: _my_service._tcp.local
resource_ttl refers to the amount of time in seconds your service will be cached in the dns responder.
set enable_loopback to true if you may have more than one instance of your service running in the same machine
Add the given ip address to discovery as A or AAAA record, advertise will happen as soon as there is at least one ip and port registered
Add the given port to discovery as SRV record, advertise will happen as soon as there is at least one ip and port registered
Add the given socket address to discovery as SRV and A or AAAA records, there will be an advertise just after adding the address
Remove all addresses from service discovery
Return the addresses of all known services