I'm working on an iPhone app that requires a basic client/server interaction model. For this I am going to use Bonjour and NSNetService, along with NSNetServiceBrowser to discover others on the same network. 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, i.e. I get the 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 iPhones, neither device can see the other's NSNetService.
- Running on the iPhone Simulator, it will find all NSNetServices, including its own.
Screenshot of 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. Any idea what is going on here?