简体   繁体   English

NSNetService / Bonjour发现仅适用于iPhone模拟器

[英]NSNetService/Bonjour discovery only works on iPhone simulator

I'm working on an iPhone app that requires a basic client/server interaction model. 我正在开发一个需要基本客户端/服务器交互模型的iPhone应用程序。 For this I am going to use Bonjour and NSNetService, along with NSNetServiceBrowser to discover others on the same network. 为此,我将使用Bonjour和NSNetService以及NSNetServiceBrowser来发现同一网络上的其他服务器。 I have followed several different guides which more or less have the same sample code. 我遵循了几个不同的指南,这些指南或多或少具有相同的示例代码。

Relevant Server Code 相关服务器代码

...
serverName = [[UIDevice currentDevice] name];
netService = [[NSNetService alloc] initWithDomain:@"local."
                                             type:@"_myservice._tcp."
                                             name:serverName
                                             port:port];
...

The service publishes successfully, ie I get the netServiceDidPublish: callback 服务成功发布,即得到netServiceDidPublish:回调

Relevant Browser Code 相关浏览器代码

...
browser = [[NSNetServiceBrowser alloc] init];
[browser setDelegate:delegate];
[browser searchForServicesOfType:@"_myservice._tcp." 
                        inDomain:@"local."];
...

Now the result of all this is interesting: 现在所有这些的结果都很有趣:

  1. Running on an iPhone, the device can only see its own published NSNetService. 在iPhone上运行,该设备只能看到其自己发布的NSNetService。
  2. Running on 2 iPhones, neither device can see the other's NSNetService. 在两部iPhone上运行时,两台设备都看不到对方的NSNetService。
  3. Running on the iPhone Simulator, it will find all NSNetServices, including its own. 运行在iPhone Simulator上,它将找到所有 NSNetServices,包括它自己的。

Screenshot of iPhone Simulator iPhone Simulator的屏幕截图

在此处输入图片说明

I'm sort of at a loss here... The simulator is working exactly as expected. 我有点不知所措...模拟器完全按预期工作。 However on the device it is not, I cannot get 2 different iPhones on the same WiFi to see each other, they only see themselves. 但是在设备上却不是,我无法在同一WiFi上让两部不同的iPhone互相看到,它们只能看到自己。 Any idea what is going on here? 知道这里发生了什么吗?

Turns out that the router that I'm on had an "SPI Firewall" enabled by default. 原来,我所在的路由器默认情况下启用了“ SPI防火墙”。 Turning this off solved the problem. 将其关闭可以解决问题。

One thing that I'm still curious about is: How come the requests coming from my Mac, both the iPhone Simulator and a Bonjour Browser, were able to get through this firewall but 3 different iPhones were not? 我仍然好奇的一件事是:来自我的Mac(iPhone模拟器和Bonjour浏览器)的请求如何能够通过此防火墙,而3部不同的iPhone却无法通过?

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

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