Creating an echo server that uses Bonjour to advertise the service
Now that we know how to publish, find, and resolve a service, let's put it all together with an actual service to connect to. In this recipe, we will take the echo server that we created in Chapter 2, Apple Low-level Networking, and add the code to publish the service with Bonjour.
The downloadable code for this chapter contains an iOS application that uses both the CFSocketServer
class (from Chapter 2, Apple Low-level Networking) and the BonjourPublishServices
class (from this chapter). The application, once the user clicks on the Start button, will attempt to publish the service; however, the echo server will start when the application first starts up. Keep in mind that publishing the service and implementing the service are two separate processes and do not actually depend on each other. When the application first starts up, the screen looks like the following screenshot:
The Bonjour Status label shows that the service has...