Opening NSNetService / Bonjour only works on iPhone simulator

I am working on an iPhone application that requires a basic client / server interaction model. For this, I'm going to use Bonjour and NSNetService together with NSNetServiceBrowser to discover others on the same network. I have completed several different tutorials that more or less have the same code example.

Corresponding server code

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

The service is published successfully, that is, I get netServiceDidPublish: callback

Relevant Browser Code

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

Now the result of all this is interesting:

  • Running on an iPhone, the device can only see its own published NSNetService.
  • Running on 2 iPhone, none of the devices can see another NSNetService.
  • Running on iPhone Simulator, it will find all NSNetServices, including its own.

Screenshot from iPhone Simulator

enter image description here

I don’t seem to understand ... The simulator works exactly as expected. However, this is not the case on the device, I can’t get 2 different iPhones on the same Wi-Fi to see each other, they see themselves. Any idea what is going on here?

+4
source share
1 answer

It turns out that the router I'm working on is set to "SPI Firewall" by default. Turning this solution off solved the problem.

One thing that I'm still interested in: why were requests coming from my Mac, both iPhone Simulator and Bonjour Browser, able to go through this firewall, but there weren’t 3 different iPhones?

+2
source

All Articles