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

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top