Important: this post assumes that you have knowledge on Qt and CMake/QMake, and that you have at least some concept on library linking.
The KDE Frameworks provides a set of frameworks based on Qt framework. It can largely reduce duplicated work on implementing lots of common-use components in many Desktop Applications. The KDE Frameworks not only support Linux/Unix Desktop, most of its frameworks can also work on Windows, macOS, even Android and iOS.
DNS Service Discovery(DNS-SD) is a way of using standard DNS programming interfaces, servers, and packet formats to browse the network for services. The protocol is widely used in the modern applications to provide inter-discovery functionality between devices, for example, printer discovery, Local Area Network multiplayer game, etc.
The KDNSSD framework is located at the Layer 1 in the KDE Frameworks, which means that KDNSSD doesn’t rely on any other framework in the KDE Frameworks. It does require Qt, but it’s not a big barricade. If you don’t have Qt development kit, you can easily install one and then continue.
In most Linux distribution, in particular, the Linux distribution which has KDE desktop support, there should be software packets of KDNSSD.
sudo apt install libkf5dnssd libkf5dnssd-dev
On RedHat family (CentOS, Fedora) :
sudo yum install kf5-kdnssd kf5-kdnssd-devel
On Arch Linux:
sudo pacman -S kdnssd
The development files (eg. header files) and the runtime libraries should be installed and configured correctly.
According to the documentation, you can use either CMake or QMake:
QT += KDNSSD
Even, you could use pkg-config if you’d like.
Here I choose to use CMake, the one mostly used in KDE Community.
The first lesson in Computer Engineer is usually a
Hello World, which contains the most basic functionality.
In KDNSSD, or DNS-SD, the most basic one is to expose a service and to discover a service. So, the
Hello World here is to expose a service on the local machine, and discover it
Firstly, I create a
ServicePublisher class in
service_publish.cpp, as the service exposer program.
Its constructor creates a
KDNSSD::PublicService object, which pretends there is a
My files service based on HTTP and thus TCP protocol, listening on
Then, we set up a connection between signal and slot. And finally publish the DNS-SD information asynchronously.
ServicePubisher() // Typo
published signal is connected to
isPublished method in the class. It will output the publish state once the state is notified:
void isPublished(bool state)
Then, I created another class
ServiceExplorer to try discovering services which are declared to be based on HTTP and TCP protocol.
serviceRemoved signals are connected with anonymous functions, which only do some output.
At the end, add the 2 programs as executable and link them to the KDNSSD:
Build and run them 😃 You should be able to discover the fake
My Files service published by the
You can find the source code on my kde-frameworks-tutorial GitHub repo. Give me and my project a star if you like it 😃 You can also watch it to get notified when there is an update.
Here I only show a basic use of KDNSSD. To know more details about it, reading documentation is the best way. Good luck!
For further reading, you could find the links in Reference chapter.
 KDE Frameworks, https://kde.org/products/frameworks/
 DNS-SD, http://www.dns-sd.org/
 RFC 6763 DNS-Based Service Discovery, https://www.ietf.org/rfc/rfc6763.txt
 KDNSSD Dcoumentation, https://api.kde.org/frameworks/kdnssd/html/index.html