Creating an echo client that uses Bonjour to discover the service
In the previous recipe, we used the CFSocketServer
and BonjourPublishServices
classes to create an echo server and to publish it. In this recipe, we will be using CFSocketClient
, BonjourBrowserService
, and BonjourResolverService
to find the echo server and to connect to it.
The downloadable code for this chapter contains a BonjourEchoClient
project that will search for servers published by the BonjourEchoServer
project, which was covered in the Creating an echo server that uses Bonjour to advertise the service recipe, and then we will send a text string to the server. The server should respond back with the same string that we sent.
If the client is unable to find any published echo servers, the app would look like the following screenshot:
Since our client is set up to continuously pool, once a server is published, the client will detect it and list the server in the Send to box. The screen will look like the following screenshot...