Bonjour 可以浏览具有特定名称的服务吗?
Bonjour 提供“DNSSD.browse(serviceType,callBackObject)”方法来浏览特定类型的服务。如果找到给定类型的服务,Bonjour 会调用“callBackObject.serviceFound”。如果服务丢失,Bonjour 会调用“callBackObject.serviceLost”。
我一直认为“DNSSD.browse”是监视特定服务的方法。 Bonjour 监视特定服务,并在服务被发现(可用)或丢失(不可用)时调用必要的方法。
但后来我意识到“DNSSD.browse”接收(作为参数)一种服务类型(例如“http.tcp”),并且可以有多种这种类型的服务。因此,如果找到或丢失任何指定类型的服务,它可能分别调用“serviceFound”和“serviceLost”。
但在我的应用程序中,我只想浏览一项特定服务。最好的方法是什么?我有两个可能的解决方案:
当我注册服务时,我给它一个唯一的类型。例如:“server1.http.tcp”。
我使用唯一名称(而不是类型)注册服务,并要求 Bonjour 浏览具有特定名称的服务。但我不确定 Bonjour 是否提供了这种可能性。它可以浏览具有特定名称的服务吗?
Bonjour provides "DNSSD.browse(serviceType,callBackObject)" method which browses for services of a particular type. If a service of the given type is found, Bonjour calls "callBackObject.serviceFound". If the service is lost, Bonjour calls "callBackObject.serviceLost".
I alway considered "DNSSD.browse" as a method for monitoring a particular service. Bonjour monitors a particular service and calls necessary method if the service is found (available) or lost (not available).
But than I realized that "DNSSD.browse" receives (as argument) a type of service (for example "http.tcp") and there can be several services of this type. So, its probably calls "serviceFound" and "serviceLost" if any service of the specified type is found or lost, respectively.
But in my application I would like to browse just for one particular service. What is the best way to do it? I have two potential solutions:
When I register a service, I give it a unique type. For example: "server1.http.tcp".
I register services with unique names (not types) and ask Bonjour to browse for services with particular names. But I am not sure that Bonjour provide such possibility. Can it browse for services with specific names?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的第一个选择是最好的。服务名称可以有一个
添加到其中的服务实例名称,以便您的服务可以具有
您建议的名称(但带有适当的下划线),
“server1._http._tcp”。使用该服务名称,该服务应该
浏览“_http._tcp”和“server1._http._tcp”时显示
如果您想要更具体的查询。 DNSSD.browse 应该有
完全支持这种类型的服务名称。
Your first option strikes me as the best one. Service names can have a
service instance name added to them so your service could have the
name you suggest (but with appropriate underscores),
"server1._http._tcp". With that service name the service should
show up when browsing for "_http._tcp" and for "server1._http._tcp"
if you want a more particular query. DNSSD.browse should have
full support for service names of this type.