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
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?
source share