I'm writing a little Tcl/Tk script, that uses a (custom) web-application (written in Python) to retrieve information from some central storage.
Everything works nicely, but only as long as the address of the webserver is known beforehand.
So I thought about adding some kind of service discovery, where my script would discover all running instances of my web-application on the local network, and automatically use them.
My first idea was to use Zeroconf/Bonjour/Avahi, and have my web-application publish a _my-web-service._tcp service with the actual query path (that the tcl client script should use to access the data) encoded in the TXT field:
avahi-publish-service MyService _my-web-service._tcp 8000 path=/data
Unfortunately, I haven't found anything that brings zeroconf-like service-discovery into the Tcl-world.
In particular, I was looking at the DNS entry on the Tcl Wiki but that only gets me as far as mDNS (and i currently have no clue how to proceed from there to zeroconf stack).
I'm not especially bound to Zeroconf/Bonjour/Avahi, but would like to run my script on Linux/Windows/macOS, and keep my build requirements minimal (that is: i would prefer it, if i don't have to compile my own wrapper code to interface with the service-discovery for each platform). Telling the users to install Bonjour or whatnot from 3rd-party sources would be tolerable though.
You were looking at the right corner, but the code snippet at the Tcl'ers Wiki appears outdated. I was curious and gave it some love.
This was tested using:
... and by announcing an exemplary service on macOS via:
I managed to discover the above service using the patched
dnspackage, by retrieving the DNS-SD (RFC 6763) specific records, mainly the target and port from theSRVrecord(s), and extras (e.g., a path) from the correspondingTXTrecord(s):This will print:
Patching tcllib's
dnsThe snippet from Tcl'ers Wiki needs to be modified, yielding:
Background:
udpAPI (udp_confis replaced bychan configure /socket/ -remote)-mcastadd).dnsis capable of decoding the DNS resource records (SRV, TXT) etc. just fine.This way, you do not have to interface with any third-party library or
execto some executable (dns-sd), but you will have to bundle your Tcl/Tk script with the platform-specific TclUDP extension, as a starpack or starkit, maybe?