Code Monkey home page Code Monkey logo

qtzeroconf's Introduction

QZeroConf is a Qt wrapper class for ZeroConf libraries across various platforms.

QZeroConf wraps avahi-client on Linux, avahi-core on Android, and dnssd on Mac, iOS and Windows.

Building

QZeroConf can be built directly into your project if your project is LGPL3 compatible. If your project is closed source, you can build QZeroConf as a dynamic library and link against it.

Building into your project

  1. Clone or download QZeroConf. If you download, unzip.

  2. Copy the qtzeroconf directory to be under your project's directory.

  3. Include the qtzeroconf.pri file in your projects .pro file

    include(qtzeroconf/qtzeroconf.pri)

  4. Add QZEROCONF_STATIC define in your projects .pro file

    DEFINES= QZEROCONF_STATIC

Compiling as a dynamic library

  1. Clone or download QZeroConf. If you download, unzip.
  2. Enter the qtzeroconf directory, run qmake and then make.

API

Service Publishing

(See the example included with the source)

  1. Include header
#include "qzeroconf.h"
  1. Create an instance of QZeroConf
QZeroConf zeroConf;

It is recommend, but not required, that you connect a slot to QZeroConf's error() signal and servicePublished() signal.

  1. If you want to add one or more txt records to the service, call
zeroConf.addServiceTxtRecord("name", "value");

or

zeroConf.addServiceTxtRecord("nameOnly");

before calling startServicePublish()

  1. Call startServicePublish() with the name, type, domain and port of your service.
zeroConf.startServicePublish("Test", "_test._tcp", "local", 12345);

QZeroConf will emit servicePublished() if successful, or the error() signal if registration fails.

Service publishing can be stopped by calling stopServicePublish(). Only one service can be published per instance of QZeroConf.

Service Discovery

(See the example included with the source)

  1. Include header
#include "qzeroconf.h"
  1. Create an instance of QZeroConf
QZeroConf zeroConf;

It is recommend, but not required, that you connect a slot to QZeroConf's error() signal.

  1. Connect a slot to QZeroConf's serviceAdded() signal. When serviceAdded() is emitted, it passes the QZeroConfService recently discovered. QZeroConfServices are shared objects. They are safe to use between threads.

  2. Optionally connect a slot to QZeroConf's serviceRemoved() signal to received status when the service is unpublished. ServiceRemoved() passes the QZeroConfService being removed.

  3. Call startBrowser() with the type of the service to browse for and optionally the protocol to use.

startBrowser("_test._tcp");

If you are browsing for services published using both ipv4 and ipv6 ( QAbstractSocket::AnyIPProtocol) you should also connect a slot to QzeroConf's serviceUpdated() signal. When the IP address of the first protocol is resolved, serviceAdded() is emitted, when the IP address of the second protocol is resolved, serviceUpdated() is emitted.

Only one browser can be in use per instance of QzeroConf.

Txt records are placed into a QMap called txt within the discovered service. For example, the value of txt record "Qt=The Best!" can be retrieved with the code...

qDebug() << zcs->txt["Qt"];

QML

QZeroConf can be used in QML applications

Build Dependencies

Qt5

On Linux, libavahi-client-dev and libavahi-common-dev

Apple App Store deployment

Publishing GPL software in the App Store is a violation of the GPL. If you need to publish an app in the Apple App Store that uses QZeroConf, please contact me for a copy of QZeroConf with a BSD licence.

iOS device sleep

When iOS puts the device to sleep, it breaks the DNS-SD browser and service publisher. The only way around this is to call stopServicePublish() and stopBrowser() when the application state changes to Qt::ApplicationSuspended (sleep) and then call startPublish() and startBrowser() when the application state changes to Qt::ApplicationActive (wake). See appStateChanged() in example.

qtzeroconf's People

Contributors

cameronklein avatar jbagg avatar mattes-bru avatar mincequi avatar mzanetti avatar pgquiles avatar strfry avatar viktorgino avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.