使用 Python 在 LAN 上发布和查找服务的正确方法
我的应用程序打开一个 TCP 套接字,并使用同一应用程序等待网络上其他用户的数据。同时,它可以向网络上的指定主机广播数据。
目前,我需要手动输入目标主机的IP才能发送数据。我希望能够找到运行该应用程序的所有主机的列表,并让用户选择向哪个主机广播数据。
Bonjour/ZeroConf 是实现这一目标的正确途径吗? (我希望它能够跨平台 OSX/Win/*Nix)
My app opens a TCP socket and waits for data from other users on the network using the same application. At the same time, it can broadcast data to a specified host on the network.
Currently, I need to manually enter the IP of the destination host to be able to send data. I want to be able to find a list of all hosts running the application and have the user pick which host to broadcast data to.
Is Bonjour/ZeroConf the right route to go to accomplish this? (I'd like it to cross-platform OSX/Win/*Nix)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是不合逻辑的。
我假设您实际上并不是指广播,而是指 单播 或只是“发送” ?
这实际上取决于您的目标环境以及您的应用程序的用途。
正如 Ignacio 指出的那样,您需要在 Windows 上安装 Apple 软件,Zeroconf/mDNS 目前才能工作。
这可能适合小型办公室/家庭使用。
然而,较大的网络可能会因各种原因禁用第 2 层组播,此时您的应用程序可能会遇到麻烦。
如果您希望它在企业环境中工作,则需要进行一些配置,但这不必在边缘(在应用程序客户端实例中)完成。
可以通过 DHCP 选项,或通过 DNS 服务记录。在这些情况下,您可能会编写一个可查询服务器来跟踪活动客户端。很像 BitTorrent 跟踪器。
设计网络应用程序时需要考虑两件事:
This is a non-sequitur.
I'm presuming that you don't actually mean broadcast, you mean Unicast or just "send"?
This really depends on your target environment and what your application is intended to do.
As Ignacio points out, you need to install the Apple software on Windows for Zeroconf/mDNS to work at the moment.
This might be suitable for small office / home use.
However larger networks may have Layer 2 Multicast disabled for a variety of reasons, at which point your app might be in trouble.
If you want it to work in the enterprise environment, then some configuration is required, but that doesn't have to be done at the edge (in the app client instances).
Could be via a DHCP option, or by DNS service records.. in these cases you'd possibly be writing a queryable server to track active clients.. much like a BitTorrent Tracker.
Two things to consider while designing your networked app:
在这种情况下,Zeroconf/DNS-SD 是一个很好的主意。它由 OS X 和 Windows 上的 Bonjour 提供(但在 Windows 上必须单独安装或作为 Apple 产品的一部分),以及 FOSS *nix 上的 Avahi 提供。
Zeroconf/DNS-SD is an excellent idea in this case. It's provided by Bonjour on OS X and Windows (but must be installed separately or as part of an Apple product on Windows), and by Avahi on FOSS *nix.
我认为 ZeroConf 是一个非常好的开始。您可能会发现此文档很有用。
I think that ZeroConf is a very good start. You may find this document useful.
我在网页上有一个列表,如果您需要互联网通信,那就太好了。
我最初的想法是添加防火墙打孔等等,但我只是无法打扰太多使用外部 IP 的主机,因为这是一个问题。
但我真的推荐 Zeroconf,至少如果你使用 Linux+ MacOSX,完全不了解Windows。
I have a list on a webpage, nice if you need internet communications.
My initial idea was to add firewall punching and all that, but I just couldn't be bothered too many of the hosts where using external IPs for it to be a problem..
But I really recommend Zeroconf, at least if you use Linux+MacOSX, don't know about Windows at all.