Resolving a Bonjour service
Now that we are able to publish and find the services, we need to be able to resolve the service so that we can connect to it. By resolving the service, we mean that we need to get the information required to establish a network connection with the actual service. This information will be the port number and either the hostname or the IP address information to connect to.
If you are going to save the connection information to connect at a later stage, you will want to save the hostname and port combination. If you are going to connect right away, you can get the sockaddr
structure from the
NSNetService
object and use this to connect. It is recommended that you do not store the address information for future connections because the IP address can change, especially on a network that uses DHCH.
For the example code, we will be using the sockaddr
structure to connect because it fits nicely in our BSD and CFNetwork examples. We will also show you how to pull out the...