Hello,
I was trying to use peer-to-peer networking between 2 iOS 8 devices but could not figure out how to keep the 2 apps from randomly disconnecting, so I thought I’d try to use bonjour. However, I can’t find an advertised service using the same devices I used when trying to communicate through a p2p connection.
The advertiser code looks like this…
+ (NSString*) proctorServiceType
{
return @"_ick._tcp";
}
- (BOOL) startAdvertisingWithPatientName : (NSString*) patientName
{
if( ! [self setupListeningSocket])
return NO;
proctorService = [[NSNetService alloc] initWithDomain:@"" type:[BonjourProctorAdvertiser proctorServiceType] name:@"" port:servicePort];
if(proctorService == nil)
return NO;
proctorService.delegate = self;
[proctorService publish];
return YES;
}
servicePort is 0.
When I run this, my
- (void) netServiceDidPublish : (NSNetService *)sender
delegate method is getting called.
However, the client side of the app, configured like this…
- (void) startBrowsingForProctorService
{
NSNetServiceBrowser *serviceBrowser = [self getProctorServiceBrowser];
[serviceBrowser setDelegate:self];
[serviceBrowser searchForServicesOfType:[BonjourProctorAdvertiser proctorServiceType] inDomain:@""];
}
- (NSNetServiceBrowser*) getProctorServiceBrowser
{
if(proctorServiceBrowser == nil)
{
proctorServiceBrowser = [[NSNetServiceBrowser alloc] init];
}
return proctorServiceBrowser;
}
never discovers the service.
I checked that both devices are on the same WiFi network. That network has other bonjour devices on it that I can discover; an HP printer for example. I enabled bonjour in Safari, but it did not see my service, though I don’t know if Safari searches for anything other than _http._tcp. Changing my advertised service type to _http._tcp didn’t result in Safari finding it, but that was a long shot anyway.
The other thing I tried was removing both devices from any WiFi network but that didn’t change the client not being able to discover the service, even though the netServiceDidPublish delegate is getting called when I select no WiFi connection.
I’m not sure where to go from here, so any pointers would be appreciated.