QMdnsEngine  0.1.0
Multicast DNS library for Qt applications
QMdnsEngine Documentation

QMdnsEngine provides an implementation of multicast DNS as per RFC 6762.

Some of QMdnsEngine's features include:

Build Requirements

QMdnsEngine requires the following in order to build the library:

Build Instructions

QMdnsEngine uses CMake for building the library. The options shown below allow the build to be customized:

Basic Provider Usage

To provide a service on the local network, begin by creating a Server, a Hostname, and a Provider:

QMdnsEngine::Server server;
QMdnsEngine::Hostname hostname(&server);
QMdnsEngine::Provider provider(&server, &hostname);

The server sends and receives raw DNS packets. The hostname finds a unique hostname that is not in use to identify the device. Lastly, the provider manages the records for a service.

The next step is to create the service and update the provider:

QMdnsEngine::Service service;
service.setType("_http._tcp.local.");
service.setName("My Service");
service.setPort(1234);
provider.update(service);

That's it! As long as the provider remains in scope, the service will be available on the local network and other devices will be able to find it.

Basic Browser Usage

To find services on the local network, begin by creating a Server and a Browser:

QMdnsEngine::Server server;
QMdnsEngine::Cache cache;
QMdnsEngine::Browser browser(&server, "_http._tcp.local.", &cache);

The cache is optional but helps save time later when resolving services. The browser is provided with a service type which is used to filter services.

To receive a notification when services are added, connect to the Browser::serviceAdded() signal:

QObject::connect(&browser, &QMdnsEngine::Browser::serviceAdded,
[](const QMdnsEngine::Service &service) {
qDebug() << service.name() << "discovered!";
}
);

To resolve the service, use a Resolver:

QMdnsEngine::Resolver resolver(&server, service.name(), &cache);
QObject::connect(&resolver, &QMdnsEngine::Resolver::resolved,
[](const QHostAddress &address) {
qDebug() << "resolved to" << address;
}
);

Note that Resolver::resolved() may be emitted once for each address provided by the service.