nsnetservicebrowser not finding nearby devices with some routers

I am developing a 3D Wi-Fi multiplayer game for iPhone and iPad without using any game engine. In my game, the list of nearby devices is displayed to user (present on same local Wi-Fi network).To find devices I am using nsnetservicebrowser class.


I found that the list is not showing or takes a lot of time to show nearby devices even if it is present on the same Wi-Fi network. Sometimes the devices name appears on the list even if it is not available on the network. I found that the issue happens with my ADSL router (Wireless N), but when I use ethernet router (Wireless G) or mobile hotspot (created from my Android device), then the list shows the nearby devices and updates properly.

I have two questions:

  1. Is this issue router specific? If yes, what kind of router settings can cause such issue?
  2. Are there any changes in the code required to make it work with all kind of routers?

I’d appreciate any suggestions on this issue. Thank you in advance.


Code snippets:

1. To search for nsnetservice

-(BOOL)searchForServicesOfType:(NSString *)type inDomain:(NSString *)domain {

[self stopCurrentResolve];

[self.netServiceBrowser stop];

[self.services removeAllObjects];

NSNetServiceBrowser *aNetServiceBrowser = [[NSNetServiceBrowser alloc] init];

if(!aNetServiceBrowser) { return NO; }

aNetServiceBrowser.delegate = self;

self.netServiceBrowser = aNetServiceBrowser;

[aNetServiceBrowser release];

[self.netServiceBrowser searchForServicesOfType:type inDomain:domain];

[self.tableView reloadData]; return YES;

}


To publish nsnetservice

self.netService = [[NSNetService alloc] initWithDomain:domain type:protocol name:name port:self.port]; if(self.netService == nil) return NO; [self.netService scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; [self.netService publish]; [self.netService setDelegate:self]; return YES;

Is this issue router specific?

I’ve seen lots of problems where buggy Wi-Fi access points (APs) cause Bonjour to misbehave. Bonjour requires that Wi-Fi multicast works correctly. Wi-Fi multicast is a relatively infrequently used feature otherwise, so it’s not uncommon to see APs that don’t implement it properly.

This is especially true for APs built in to DSL gateways. The first thing I do when I install a new DSL gateway at home is disable its Wi-Fi and connect my trusty AirPort base station (in bridge mode) to provide reliable Wi-Fi service.

If yes, what kind of router settings can cause such issue?

If the problem occurs 100% of the time, you should look to see if the AP has a specific UI to enable multicast. High-end APs typically have such a feature because multicast is a relatively expensive operation on Wi-Fi, so enterprise environments will sometimes want to disable or limit it.

If the problem is intermittent then you should try restarting the AP. A lot of the time that helps.

If you want to test your code with a known good AP, use something from Apple (an AirPort base station or a Time Capsule). This has two advantages:

  • Apple APs work reliably, especially with multicast — As you might imagine, Apple APs get lots of testing with Bonjour.

  • If there is a problem, you only have one person to blame.

Are there any changes in the code required to make it work with all kind of routers?

No.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
  • Thank you for your suggestions. It was helpful to know the information provided by you. I have checked my router settings and there is no specific UI to enable multicast. Are there any other router settings I can try to speed up this discovery process? or there is any other workaround solution for this issue?
  • Is this issue is router specific? If yes, why the issue happens only with these types of routers?

Are there any other router settings I can try to speed up this discovery process?

I’m not able to provide insight into non-Apple kit. On Apple APs there is no UI to configure multicast support; it works out of the box and continues to work as long as the AP is functioning.

or there is any other workaround solution for this issue?

As I mentioned earlier, restarting the AP often helps.

Is this issue is router specific?

I’m not sure why you’re asking me that. You started this thread by saying that the problems you’re seeing only occur on some APs, implying that, yes, this is AP-specific.

If yes, why the issue happens only with these types of routers?

I’m going to quote myself here: I’ve seen lots of problems where buggy Wi-Fi access points (APs) cause Bonjour to misbehave.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
nsnetservicebrowser not finding nearby devices with some routers
 
 
Q