Broadcast http on mDNS Bonjour in Catalina?
As of Catalina I've quit Apache and switched to Tornado. Apache was easy to configure http Zeroconf broadcast port 80 on the LAN. What I am looking for is an Avahi type solution where I can configure services independent of the originating process.
How would I do it when using another server software like Tornado?
Solution 1:
You’ve got several choices here of existing libraries of open source code with quite good documentation. In essence, your server needs to know an IP address and then drop the service advertisement.
Here’s JavaScript code to add http listener advertisement from one node.js based implementation:
var browser = mdns.createBrowser(mdns.tcp('http'), {resolverSequence: sequence});
Since you mentioned Tornado - you might be interested in a python zeroconf library that does the same and also lists Avahi compatibility in addition to Zeroconf.
The example code to advertise a fake HTTP server is a bit longer than the node call above, but the code is all open source. Making a real HTTPS server isn’t much more code, so you might be close to your solution here.
- https://github.com/jstasiak/python-zeroconf/blob/master/examples/registration.py
The core is what you’d expect - list the details and then advertise...
info = ServiceInfo(
"_http._tcp.local.",
"Paul's Test Web Site._http._tcp.local.",
addresses=[socket.inet_aton("127.0.0.1")],
port=80,
properties=desc,
server="ash-2.local.",
)
zeroconf = Zeroconf(ip_version=ip_version)
print("Registration of a service, press Ctrl-C to exit...")
zeroconf.register_service(info)