使用 Python 在 LAN 上发布和查找服务的正确方法

发布于 2024-10-05 23:55:50 字数 206 浏览 12 评论 0原文

我的应用程序打开一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

半﹌身腐败 2024-10-12 23:55:50

它可以将数据广播到网络上的指定主机

这是不合逻辑的。

我假设您实际上并不是指广播,而是指 单播 或只是“发送” ?

Bonjour/ZeroConf 是实现这一目标的正确途径吗?

这实际上取决于您的目标环境以及您的应用程序的用途。

正如 Ignacio 指出的那样,您需要在 Windows 上安装 Apple 软件,Zeroconf/mDNS 目前才能工作。

这可能适合小型办公室/家庭使用。


然而,较大的网络可能会因各种原因禁用第 2 层组播,此时您的应用程序可能会遇到麻烦。

如果您希望它在企业环境中工作,则需要进行一些配置,但这不必在边缘(在应用程序客户端实例中)完成。

可以通过 DHCP 选项,或通过 DNS 服务记录。在这些情况下,您可能会编写一个可查询服务器来跟踪活动客户端。很像 BitTorrent 跟踪器。

设计网络应用程序时需要考虑两件事:

  • 是否有理由在网络上运行多个应用程序“安装”?
  • 始终考虑版本控制的含义:一个客户端比另一个客户端更新,他们仍然可以相互通信或者至少可以优雅地失败吗?

it can broadcast data to a specified host on the network

This is a non-sequitur.

I'm presuming that you don't actually mean broadcast, you mean Unicast or just "send"?

Is Bonjour/ZeroConf the right route to go to accomplish this?

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:

  • Would there ever be reason to run more than one "installation" of your application on a network?
  • Always consider the implications of versioning: One client is more up to date than another, can they still talk to each other or at least fail gracefully?
—━☆沉默づ 2024-10-12 23:55:50

在这种情况下,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.

帅气尐潴 2024-10-12 23:55:50

我认为 ZeroConf 是一个非常好的开始。您可能会发现此文档很有用。

I think that ZeroConf is a very good start. You may find this document useful.

凉薄对峙 2024-10-12 23:55:50

我在网页上有一个列表,如果您需要互联网通信,那就太好了。

<dl_service updated="2010-12-03 11:55:40+01:00">
 <client name="internal" ip="10.0.23.234" external_ip="1.1.1.1"/> 
 <client name="bigone" ip="2.2.2.2" external_ip="2.2.2.2">
  <messsage type="connect" from="Bigone" to="internal" />
 </client> 
</dl_service>

我最初的想法是添加防火墙打孔等等,但我只是无法打扰太多使用外部 IP 的主机,因为这是一个问题。

但我真的推荐 Zeroconf,至少如果你使用 Linux+ MacOSX,完全不了解Windows。

I have a list on a webpage, nice if you need internet communications.

<dl_service updated="2010-12-03 11:55:40+01:00">
 <client name="internal" ip="10.0.23.234" external_ip="1.1.1.1"/> 
 <client name="bigone" ip="2.2.2.2" external_ip="2.2.2.2">
  <messsage type="connect" from="Bigone" to="internal" />
 </client> 
</dl_service>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文