TCL中的服务发现
我正在编写一些TCL/TK脚本,该脚本使用(自定义)Web应用程序(用Python编写)来从某些中央存储中检索信息。
一切都很好,但是只有事先已知Web服务器的地址。
因此,我考虑了添加某种服务发现,我的脚本将在本地网络上发现我的Web应用程序的所有运行实例,并自动使用它们。
我的第一个想法是使用zeroconf/bonjour/avahi,并让我的网络应用发布_my-web-service._tcp
使用实际查询路径(TCL客户端脚本应访问该服务)数据)在txt
字段中编码:
avahi-publish-service MyService _my-web-service._tcp 8000 path=/data
不幸的是,我还没有找到 将类似zeroconf的服务 - 发现带入tcl-world。
特别是,我正在看 dns tcl wiki ,但这只有得到我就mdns
(我目前不知道如何从那里到达Zeroconf堆栈)。
我并不是特别绑定到zeroconf/bonjour/avahi,而是想在linux/windows/macos,和上运行我的脚本我不必编译自己的包装代码即可与每个平台的服务划分进行交互)。不过,告诉用户安装Bonjour或第三方来源的Whatot将是可以忍受的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在查看右角,但是看起来已经过时了。我很好奇,给了一些爱。
使用以下方式对此进行了测试:
...并通过在MacOS上宣布示例性服务:
我设法使用修补的
dns
软件包发现了上述服务,通过检索DNS-SD(RFC 6763)特定记录。 例如,路径)的目标和端口记录(
,主要是
srv
tcllib的dns
来自 tcl'ers wiki 需要修改,产量:
背景:
udp
api(udp_conf
由chan configure/socket/socket/-rememote
)代替-mcastadd
)。dns
能够解码DNS资源记录(SRV,TXT)等。,您无需与任何第三方库或
exec
与某些可执行文件接口(dns-sd
),但是您将不得不将TCL/TK脚本与平台特定的TCLUDP扩展程序捆绑在一起,也许是Starpack或Starkit?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
dns
package, by retrieving the DNS-SD (RFC 6763) specific records, mainly the target and port from theSRV
record(s), and extras (e.g., a path) from the correspondingTXT
record(s):This will print:
Patching tcllib's
dns
The snippet from Tcl'ers Wiki needs to be modified, yielding:
Background:
udp
API (udp_conf
is replaced bychan configure /socket/ -remote
)-mcastadd
).dns
is 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
exec
to 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?