Search code examples
iosmacosbonjour

Is NSNetService only works with .local domain?


I have a code CocoaHTTPServer which publishes service using Bonjour. And tt uses NSNetService for this.

It works fine (both on OS X and iOS) if you define domain ".local". However, if you define anything else, it doesn't publish a service and it doesn't call a delegate that it didn't publish the server.

I investigated this and found following info.

Documentation from NSNetService class:

This class and the NSNetServiceBrowser class use multicast DNS to convey information about network services to and from your application.

Documentation from Bonjour domain names

On Bonjour systems, local. is used to indicate a name that should be looked up using an IP multicast query on the local IP network.

Do I understand correctly that NSNetService class can work only with .local domain and can't work with wide-area bonjour (different domains)?

P.S. If I am not missing anything, I plan to contact Apple, because it's strange to have an argument with just one correct value and all other incorrect (and not reported through any errors)


Solution

  • NSNetService does work with domains other than local..

    Before publishing your service, use NSNetServiceBrowser and - (void)searchForRegistrationDomains to find suitable registration domains.

    Apple's NSNetServices and CFNetServices Programming Guide contains a section about this including sample code: Browsing for Domains.