Struct async_zeroconf::Service [−][src]
pub struct Service { /* fields omitted */ }
Expand description
Struct representing a ZeroConf service. This should be created with all the information that should be associated with the service and then the publish method can be used to register the service. The ServiceRef returned from publish should be held for as long as the service should continue being advertised, once dropped the service will be deallocated.
Examples
Normally the default values of domain
, host
and interface
don’t need
to be changed.
let service_ref = async_zeroconf::Service::new("Server", "_http._tcp", 80)
.publish()?;
// Service kept alive until service_ref dropped
These fields can be customised if required. More details are available in the DNSServiceRegister documentation.
let service_ref = async_zeroconf::Service::new("Server", "_http._tcp", 80)
.set_domain("local".to_string())
.set_host("localhost".to_string())
.publish()?;
// Service kept alive until service_ref dropped
Implementations
Create a new Service, called name
of type service_type
that is
listening on port port
.
This must then be published with Service::publish to advertise the service.
Examples
// Create a service description
let service = async_zeroconf::Service::new("Web Server", "_http._tcp", 80);
Create a new Service, called name
of type service_type
that is
listening on port port
with the TXT records described by txt
.
This must then be published with Service::publish to advertise the service.
Examples
// Create a TXT record collection
let mut txt = async_zeroconf::TxtRecord::new();
txt.add("version".to_string(), "0.1".to_string());
// Create a service description
let service = async_zeroconf::Service::new_with_txt("Web Server", "_http._tcp", 80, txt);
Set an interface to advertise the service on rather than all.
By default the service will be advertised on all interfaces.
Prevent renaming of this service if there is a name collision.
By default the service will be automatically renamed.
Set the (optional) domain for the service.
If not specified, the default domain is used.
Set the (optional) hostname for the service.
If not set, the hostname of the host will be used.
Get the type of the service
Publish the service, returns a ServiceRef which should be held to keep the service alive. Once the ServiceRef is dropped the service will be removed and deallocated.
Arguments
allow_rename
- Allow the service to be automatically renamed if a service with the same name already exists
Examples
// Create a service description
let service = async_zeroconf::Service::new("Server", "_http._tcp", 80);
// Publish the service
let service_ref = service.publish()?;
// Service kept alive until service_ref dropped
Publish the service, returns a ServiceRef which should be held to keep the service alive and a future which should be awaited on to respond to any events associated with keeping the service registered. Once the ServiceRef is dropped the service will be removed and deallocated.
Note
This method is intended if more control is needed over how the task is spawned. Service::publish will automatically spawn the task.
Examples
// Create a service description
let service = async_zeroconf::Service::new("Server", "_http._tcp", 80);
// Publish the service
let (service_ref, task) = service.publish_task()?;
// Spawn the task to respond to events
tokio::spawn(task);
// Service kept alive until service_ref dropped
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Service
impl UnwindSafe for Service
Blanket Implementations
Mutably borrows from an owned value. Read more