does anyone know of any examples of avahi discovery in c/c++?



  • I'm trying to figure out (learn) how to discover where a WebSocket server on the local network is, and failing miserably. I can write code to successfully do it in javascript, but every library I try in c/c++ fails. If anyone can point me to an example I would greatly appreciate it.

    thx



  • Hi @davidsi,

    For my C++ home automation daemon, I needed to advertise and discover services via Avahi and wrote a Discovery class for that.

    It's not generic, ready-to-use sample code, and is not completely free of dependencies. In particular, it uses the MLTicket class from p44utils to implement regular calls to avahi_poll and for delaying advertisement.

    But I guess it could still be of use for you to see how to set up and run avahi from C++ in general, and for an example of a wrapper class for a service browser (ServiceBrowser class near the end of the source file).

    The code is such that it is normally linked against the avahi client library libavahi-client (the normal case on the Omega2, that's when the avahi daemon process is running and your app is one of possibly multiple clients using avahi services).

    But when you define USE_AVAHI_CORE as non-zero, then the code can also be linked against the avahi core library, which can be handy on really tiny embedded systems where your app is the only avahi user and you don't want the overhead of the separate avahi daemon.



  • @luz Why thank you! That's just what I was looking for. Perfect to learn from.


Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.