Discovering a Bonjour service
In this recipe, we will use the
NSNetServiceBrowser
class to look for our published service.
The NSNetServiceBrowser
class is used to find the services that are published by NSNetService
. Once we initialize the NSNetServiceBrowser
object, we need to assign a delegate, and then we can begin browsing for services. Taking into account the possibility of delays in receiving responses from the services and also because services can come online or go offline at any time, the NSNetServiceBrowser
object performs the service discovery asynchronously. The NSNetServiceBrowser
class relies on the delegate methods to handle the notifications of the services coming online or going offline.
Getting ready
This recipe is compatible with both iOS and OS X. No extra frameworks or libraries are required.
How to do it...
In this recipe, we will create a
BonjourBrowserService
class that will have all the code and callback methods required to discover services:
We will begin by creating...