I have a service that is published in Android. How to browser it in iOS?

165 views Asked by At

We are creating a multi-platform apps for both Android and iOS.
Currently, we have a services that is published in Android with these information
Type:_http._tcp or _http._udp Name: abcController port

Now, I want to browse "abcController" services in iOS apps to get the list of host (ip) for connecting. I'm trying to do it with these code

 NSString* servicesOfType = @"abcController._http._tcp.";
NSString* domain  = @"";

domainBrowser = [[NSNetServiceBrowser alloc] init];
[domainBrowser setDelegate:self];
[domainBrowser searchForServicesOfType:servicesOfType inDomain:domain];

However, it only calls netServiceBrowserWillSearch and doesn't have any response.

Any helps is very appreciate !

2

There are 2 answers

0
user2959234 On BEST ANSWER

I found the solution for my issue. It turns out that my service is published in udp, therefore. withthiscode.

- (void) initBrowsingServices
{
    NSString* servicesOfType = @"_http._udp.";
    NSString* domain  = @"local";


   domainBrowser = [[NSNetServiceBrowser alloc] init];
   [domainBrowser setDelegate:self];
   [domainBrowser searchForServicesOfType:servicesOfType inDomain:domain];

   domains = [[NSMutableArray alloc] init];

   searching = NO;
}

I can receive my service now.

0
Kenny On

Your service name needs to begin with '_' otherwise it will be confused as being a domain instead.