iPhone SDK:Bonjour 和NSNetService 名称!= 发布名称?

发布于 2024-09-03 09:25:41 字数 565 浏览 1 评论 0原文

在我的 iPhone 应用程序中,我正在发布 bonjour 服务并使用以下委托方法:

- (void)netServiceDidPublish:(NSNetService *)ns
{
   NSLog(@"Bonjour Service Published: http://%@.%@", [ns name], [ns domain]);
}

“name”属性返回设备名称“How's Testing”,这是正确的。但是,当我使用 Safari 发现可用服务时,名称为“hows-testing”——该服务为 http: //hows-testing.local.:somePortNumber

为什么发布的名称与 NSNetService 报告的名称不同?如何显示已发布服务的实际名称?假设由于某种原因,无法从对象中获取发布的名称,我该如何自己确定呢?我知道它是基于设备名称,但是替换规则是什么?删除撇号,用破折号替换空格......还有其他吗?特殊字符呢?

In my iPhone app, I'm publishing a bonjour service and using the following delegate method:

- (void)netServiceDidPublish:(NSNetService *)ns
{
   NSLog(@"Bonjour Service Published: http://%@.%@", [ns name], [ns domain]);
}

The "name" property is returning the device name, "How's Testing", which is correct. However, when I use Safari to discover available services the name is "hows-testing" -- the service is http://hows-testing.local.:somePortNumber.

Why is the published name different than what is being reported by the NSNetService? How do I display for the actual name of the published service? Assuming that, for some reason, there is no way to get the published name from the object, how do I determine it myself? I understand that it's based on device name, but what are the substitution rules? Remove apostrophes, replace spaces with dash...anything else? What about special characters?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

刘备忘录 2024-09-10 09:25:42

我相信“hows-testing”是计算机的主机名,而不是服务的名称。相反,您想要查看 hostName 属性:

- (void)netServiceDidPublish:(NSNetService *)ns
{
   NSLog(@"Bonjour Service Published: http://%@", [ns hostName]);
}

如果端口不是默认端口,您可能还应该检查 port 属性,并将其包含在 URL 中对于该协议(HTTP 为 80)

I believe that "hows-testing" is the host name of the computer, not the name of the service. Instead, you want to look at the hostName attribute:

- (void)netServiceDidPublish:(NSNetService *)ns
{
   NSLog(@"Bonjour Service Published: http://%@", [ns hostName]);
}

You should probably also examine the port attribute, and include it in the URL, if the port is something other than the default for that protocol (80 for HTTP)

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