简体   繁体   English

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

[英]iPhone SDK: Bonjour & NSNetService name != published name?

In my iPhone app, I'm publishing a bonjour service and using the following delegate method: 在我的iPhone应用程序中,我发布了一个bonjour服务并使用以下委托方法:

- (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. “name”属性返回设备名称“How's Testing”,这是正确的。 However, when I use Safari to discover available services the name is "hows-testing" -- the service is http://hows-testing.local.:somePortNumber . 但是,当我使用Safari发现可用服务时,名称是“hows-testing” - 该服务是http://hows-testing.local.:somePortNumber

Why is the published name different than what is being reported by the NSNetService? 为什么发布的名称与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? 特殊字符怎么样?

I believe that "hows-testing" is the host name of the computer, not the name of the service. 我认为“hows-testing”是计算机的主机名,而不是服务的名称。 Instead, you want to look at the hostName attribute: 相反,您想要查看hostName属性:

- (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) 您应该检查端口属性,并将其包含在URL中,如果该端口不是该协议的默认端口(HTTP为80)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM