This are some tiny networking toys for Qt based applications, written in C++17:
This library is tested to work with Qt 5.15, 6.5 and 6.8 on Android, iOS, Linux, macOS and Windows.
DNS Service Discovery, also known as "DNS-SD" and "Bonjour", is an efficient method to discover network services based. Using Multicast DNS it's a "Zeroconf" technique for local networks. Via traditional Unicast DNS it also works over the Internet.
With this library discovering DNS-SD services is as simple as this:
const auto resolver = new mdns::Resolver;
connect(resolver, &mdns::Resolver::serviceFound,
this, [](const auto &service) {
qInfo() << "mDNS service found:" << service;
});
resolver->lookupServices({"_http._tcp"_L1, "_googlecast._tcp"_L1});
The C++ definition of the mDNS resolver can be found in mdnsresolver.h. A slightly more complex example can be found in mdnsresolverdemo.cpp.
The Simple Service Discovery Protocol (SSDP) is another "Zeroconf" technique based on multicast messages. It's also the basis Univeral Plug and Play (UPnP).
With this library discovering SSDP services is as simple as this:
const auto resolver = new ssdp::Resolver;
connect(resolver, &ssdp::Resolver::serviceFound,
this, [](const auto &service) {
qInfo() << "SSDP service found:" << service;
});
resolver->lookupService("ssdp:all"_L1);
The C++ definition of the SSDP resolver can be found in ssdpresolver.h. A slightly more complex example can be found in ssdpresolverdemo.cpp.
Parsing XML documents can is pretty annoying. Maybe it is annoying less for you if you got a decent declarative XML parser at your hand. The declarative XML parser provided here easily turns such XML
<?xml version="1.0"?>
<root>
<version>
<major>1</major>
<minor>2</minor>
</version>
<icons>
<icon type="default">
<mimetype>image/png</mimetype>
<width>384</width>
<height>256</height>
<url>/icons/test.png</url>
</icon>
<icon type="banner">
<mimetype>image/webp</mimetype>
<width>768</width>
<height>512</height>
<url>/icons/test.webp</url>
</icon>
</icons>
<url>https://ecosia.org/</url>
<url>https://mission-lifeline.de/en/</url>
</root>
into such C++ data structures
struct TestResult
{
struct Icon
{
enum Type { Default, Banner };
Type type = {};
QString mimeType = {};
QSize size = {};
QUrl url = {};
QString relation = {};
};
QVersionNumber version = {};
QList<Icon> icons = {};
QList<QUrl> urls = {};
};
with as little as that:
auto result = TestResult{};
const auto states = StateTable {
{
State::Document, {
{u"root", transition<State::Root>()},
}
}, {
State::Root, {
{u"version", transition<State::Version>()},
{u"icons", transition<State::IconList>()},
{u"url", append<&TestResult::urls>(result)},
}
}, {
State::Version, {
{u"major", assign<&TestResult::version, VersionSegment::Major>(result)},
{u"minor", assign<&TestResult::version, VersionSegment::Minor>(result)},
}
}, {
State::IconList, {
{u"icon", transition<State::Icon, &TestResult::icons>(result)},
}
}, {
State::Icon, {
{u"@type", assign<&TestResult::Icon::type>(result)},
{u"mimetype", assign<&TestResult::Icon::mimeType>(result)},
{u"width", assign<&TestResult::Icon::size, &QSize::setWidth>(result)},
{u"height", assign<&TestResult::Icon::size, &QSize::setHeight>(result)},
{u"url/@rel", assign<&TestResult::Icon::relation>(result)},
{u"url", assign<&TestResult::Icon::url>(result)},
}
}
};
parse(lcExample(), State::Document, {{xmlNamespace, states}});
This library also contains a very, very minimal compressing HTTP/1.1 server. More a demonstration of the concept, than a real implementation.
- CMake 3.10
- Qt 6.5, or Qt 5.15
- C++17
This is build and tested on all the major platforms supported by Qt: Android, iOS, Linux, macOS, Windows.
Copyright (C) 2019-2024 Mathias Hasselmann Licensed under MIT License