Poco::DNSSD

class DNSSDResponder

File Information

Library: DNSSD
Package: Core
Header: Poco/DNSSD/DNSSDResponder.h

Description

DNSSDResponder provides a unified interface to the underlying DNS Service Discovery implementation, which can be Apple's Bonjour or Avahi.

An application should not create more than one instance of the DNSSDResponder class.

To register a service with the DNSSDResponder, and thus to announce a service on the network, create an instance of Service with appropriate values. Then pass this object to registerService(). Example:

DNSSDResponder dnssdResponder;
dnssdResponder.start():
...
Service::Properties props;
Service myService(0, "My Service", "_mysvc._tcp", "", "", 1234, props);
ServiceHandle myServiceHandle = dnssdResponder.registerService(myService);

Note that service registration is asynchronous, so the serviceRegistered and serviceRegistrationFailed events must be observed to ensure the service has actually been registered.

A registered service can be unregistered, by passing its ServiceHandle to unregisterService().

Before a DNSSDResponder instance can be created, registerImplFactory() must be called to register a DNSSDResponderImplFactory. This is done by calling the initializeDNSSD() function provided by an implementation library (e.g., Bonjour or Avahi).

Member Summary

Member Functions: addRecord, browser, registerImplFactory, registerService, removeRecord, start, stop, unregisterImplFactory, unregisterService, updateRecord

Nested Classes

struct ErrorEventArgs

 

struct ServiceEventArgs

 

Enumerations

RegistrationOptions

Options for service registration.

REG_LOCAL_ONLY = 0x01

Service is visible on local host only.

REG_NO_AUTORENAME = 0x02

Do not allow automatic renaming in case another service with the same name exists.

REG_NON_BROWSABLE = 0x04

Service is not visible when browsing, but can be resolved.

Constructors

DNSSDResponder

DNSSDResponder();

Creates a DNSSDResponder.

Destructor

~DNSSDResponder

~DNSSDResponder();

Destroys the DNSSDResponder.

Member Functions

addRecord

RecordHandle addRecord(
    ServiceHandle serviceHandle,
    const Record & record
);

Add a record to a registered service. The name of the record will be the same as the registered service's name.

The record can later be updated or deregistered by passing the RecordHandle returned by this function to updateRecord() or removeRecord().

browser

DNSSDBrowser & browser();

Returns the DNSServiceBrowser, which is used to discover and resolve services and domains.

registerImplFactory static

static void registerImplFactory(
    DNSSDResponderImplFactory & factory
);

Registers the factory for creating DNSSDResponderImpl objects.

A factory must be registered before the first instance of DNSSDResponder is created.

registerService

ServiceHandle registerService(
    const Service & service,
    int options = 0
);

Registers a service, specified by the given Service object.

Valid option values are defined in the RegistrationOptions enumeration.

Service registration will be asynchronously. When the service has been registered successfully, a serviceRegistered event will be fired. Otherwise, a ServiceRegistrationFailed event will be fired.

Returns a ServiceHandle that can later be used to unregister the service, or to add DNS records to the service.

removeRecord

void removeRecord(
    ServiceHandle serviceHandle,
    RecordHandle & recordHandle
);

Remove a registered resource record. The record must be a record added to a registered service via addRecord().

The RecordHandle is invalidated.

start

void start();

Starts the responder.

Must be called before services can be registered or before browsing for domains and services.

stop

void stop();

Stops the responder.

unregisterImplFactory static

static void unregisterImplFactory();

Unregisters the currently registered DNSSDResponderImplFactory.

unregisterService

void unregisterService(
    ServiceHandle & serviceHandle
);

Unregisters the service specified by serviceHandle.

The ServiceHandle is invalidated.

updateRecord

void updateRecord(
    ServiceHandle serviceHandle,
    RecordHandle recordHandle,
    const Record & record
);

Update a registered resource record. The record must either be:

  • the primary txt record of a service registered via registerService() (if recordHandle is a null handle), or
  • a record added to a registered service via addRecord().

Variables

serviceRegistered

Poco::BasicEvent < const ServiceEventArgs > serviceRegistered;

Fired after the service has been registered successfully.

If auto-rename has been enabled, the service name may be different from the name originally specified.

serviceRegistrationFailed

Poco::BasicEvent < const ErrorEventArgs > serviceRegistrationFailed;

Fired when service registration fails.

Securely control IoT edge devices from anywhere   Connect a Device