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:
- Is this issue router specific? If yes, what kind of router settings can cause such issue?
- 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;