如何使用 Bonjour 跨子网宣传服务?
我熟悉 Bonjour 在“本地”域上的广告服务的使用。我已经完成了几个例子,并且我知道我为此使用的相应的 Cocoa 类。
我很好奇如何将简单的 Bonjour 服务广告到不同的子网。具体来说,我正在尝试编写一个在通过以太网连接的桌面上运行的网络服务。客户端在通过 Wifi 连接的移动设备(iPhone/iPad)上运行。在我的网络设置中,Wifi 与以太网位于不同的子网中。然而,两者都位于防火墙后面。我不需要在防火墙外做广告,我只是希望 wifi 客户端能够看到由以太网连接的服务器广告的服务。
这可能吗?我知道 Bonjour 应该支持跨子网通信,但每当我尝试阅读此功能时,它都会深入了解 DNS 记录等内容。我是一名应用程序开发人员......我对这些东西一无所知,也不希望用户担心它。我错过了一些简单的事情吗?
I am familiar with the usage of Bonjour for advertising services on the "local" domain. I have worked through several examples, and I know the corresponding Cocoa classes I use for that.
I am curious about how I advertise a simple Bonjour service to a different subnet. Specifically, I am trying to write a network service that runs on my desktop which is connected via ethernet. The client runs on a mobile device (iPhone/iPad) that is connected via Wifi. In my network setup, the Wifi is on a different subnet than the ethernet. However, both are behind the firewall. I have no need to advertise outside the firewall, I simply want wifi clients to be able to see services advertised by a ethernet connected server.
Is this possible? I know Bonjour is supposed to support communication across subnets, but anytime I try to read about this feature it dives deep into DNS records and whatnot. I am an application developer...I have no idea about that stuff, nor do I want users to have to worry about it. Am I missing something simple?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是一个典型的编程问题,但我认为这是测试基于 Bonjour 的代码的一个巨大障碍。
Bonjour 支持两种服务器机制来通知客户端其存在,首先是本地网络上的多播,其次是 DNS。
组播很容易使用,因为无需设置,但不幸的是它只能在同一网络上使用。
DNS 可以跨路由器(互联网)工作,但它需要正确配置名称服务器和使用该名称服务器的客户端。
我认为你只有两个选择。
在第一种情况下,重要的是要认识到该服务不一定必须由在 Mac 上运行的您自己的应用程序来宣传。您可以使用实用程序
dns-sd
将任何 IP 地址/端口注册为网络上的 Bonjour 服务。为此,您需要一台连接到 WiFi 的计算机(Mac、Linux),并以与此类似的方式运行 dns-sd:这将注册一个名为“http”的服务“Stack Overflow”作为 Bonjour 服务。检查一下 - 在终端中运行它并在 Bonjour 下的 Safari 书签中检查它。您可以用同样的方式注册您的应用程序。
不幸的是,您需要在连接到 WiFi 网络的计算机上运行它。这意味着您的 Mac 应用程序将在其自己的以太网上进行广告,
dns-sd
在 WiFi 上进行广告。第二种选择有点令人恐惧,但如果您愿意参与一些管理工作,那也没什么大不了的。
同样,您不需要在 DNS 中动态注册服务。您可以简单地在 DNS 配置中对 Mac 的名称和应用程序的端口进行硬编码。这些只是需要添加到区域文件(DNS 配置文件)中的 4 行。
前两行告诉客户端(在您的情况下为 iOS 设备)该域已启用 Bonjour。第三行告诉客户端有一个
icool
类型的服务“iCool App Service”可用。第四行告诉客户端当前服务的地址和端口。客户端将为其配置的(或通过 DHCP 获取的)“搜索域”查找 DNS 条目。检查您的网络设置。
您可以在 Mac、某些 Linux 机器上运行名称服务器,也可以使用 dyndns.com 等服务。
希望这有帮助。
This is not a typical programming question, but I see it's a huge obstacle in testing your Bonjour based code.
Bonjour supports two mechanisms for servers to inform clients about their existence, multicasts on local network first, DNS second.
Multicasts are easy to use because there is no setup, unfortunately it can only be used on the same network.
DNS have the luxury of working across routers (Internet), but it requires properly configured nameserver and clients using that nameserver.
I think you are having only two options.
In the first case it is important to realize that the service doesn't necessarily have to be advertised by your own application running on a Mac. You can use utility
dns-sd
to register any IP address/port as a Bonjour service on the network. For this to work you need a machine (Mac, Linux) which is connected to your WiFi, and rundns-sd
there in a similar way to this:This would register an "http" service with name "Stack Overflow" as a Bonjour service. Check it out - run it in terminal and check it in Safari's Bookmarks under Bonjour. The same way you can register your application.
Unfortunately you need to run this on a machine connected to WiFi network. That means your Mac application will advertise on its own ethernet network,
dns-sd
advertises on WiFi.Second option is a bit frightening, but it's not a big deal if you're willing to get hands dirty with some administration.
Again, you don't need to have services dynamically registered in DNS. You can simply hard code your Mac's name and your app's port in the DNS configuration. Those are just 4 lines that need to be added to the zone file (DNS configuration file).
First two lines tells clients (iOS devices in your case) that Bonjour is enabled for this domain. Third line tells clients that there is a service "iCool App Service" of type
icool
available. Fourth line tells clients current address and port of the service.Clients will look for DNS entries for their configured (or gotten via DHCP) "Search Domains". Check your network settings.
You can run nameserver on your Mac, some Linux box, or you can use services like dyndns.com.
Hope this helps.