pub struct ServiceDiscovery { /* private fields */ }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::sync_discovery::ServiceDiscovery;
use simple_mdns::InstanceInformation;
use std::str::FromStr;
let mut discovery = ServiceDiscovery::new(
InstanceInformation::new("a".into()).with_socket_address("192.168.1.22:8090".parse().expect("Invalid Socket Address")),
"_mysrv._tcp.local",
60
).expect("Failed to create service discovery");
Implementations§
Source§impl ServiceDiscovery
impl ServiceDiscovery
Sourcepub fn new(
instance_information: InstanceInformation,
service_name: &str,
resource_ttl: u32,
) -> Result<Self, SimpleMdnsError>
pub fn new( instance_information: InstanceInformation, service_name: &str, resource_ttl: u32, ) -> Result<Self, SimpleMdnsError>
Creates a new ServiceDiscovery by providing instance_information, service_name, resource ttl. The service will be created using IPV4 scope with UNSPECIFIED Interface
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.
Sourcepub fn new_with_scope(
instance_information: InstanceInformation,
service_name: &str,
resource_ttl: u32,
on_discovery: Option<Sender<InstanceInformation>>,
network_scope: NetworkScope,
) -> Result<Self, SimpleMdnsError>
pub fn new_with_scope( instance_information: InstanceInformation, service_name: &str, resource_ttl: u32, on_discovery: Option<Sender<InstanceInformation>>, network_scope: NetworkScope, ) -> Result<Self, SimpleMdnsError>
Creates a new ServiceDiscovery by providing instance_information, service_name, resource ttl, on_disovery and network_scope
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.
on_discovery channel, if provided, will receive every instance information when
discovered
network_scope to be used
Sourcepub fn remove_service_from_discovery(&mut self)
pub fn remove_service_from_discovery(&mut self)
Remove service from discovery by announcing with a cache flush and removing all the internal resource records
Sourcepub fn get_known_services(&self) -> HashSet<InstanceInformation>
pub fn get_known_services(&self) -> HashSet<InstanceInformation>
Return the InstanceInformation of all known services
Sourcepub fn announce(&self, cache_flush: bool)
pub fn announce(&self, cache_flush: bool)
Announce the service by sending a packet with all the resource records in the answers section. It is not necessary to call this method manually, it will be called automatically when the instance is added to the discovery.
if cache_flush is true, then the resources will have the cache flush flag set, this will
cause them to be removed from any cache that receives the packet.