- How it Works
- Protocols and Remote Objects
- Using Distributed Objects
- Distributed Objects and Bonjour
- Conclusion
With 10.2, Apple introduced multicast DNS service discovery to OS X. This superseded AppleTalk service discovery with a TCP/IP-based protocol and was exposed to Cocoa via the NSNetService class. This was originally marketed as Rendezvous, until Apple discovered that they were infringing someone else's trademark and renamed it Bonjour.
The NSSocketPortNameServer class also uses Bonjour for advertising port names, which lets you implement something like anycast trivially, where you just try publishing an object with a well-known name and if that name is already in use you give up. Then, anyone requesting the object with that name will get an instance of it on some computer, but not a specific one.
Alternatively, you can combine NSNetServices with DO quite easily. If you publish the name of your object with NSNetServices and a well-known service type (e.g. _my_DO_example_service._tcp.) then you can use NSNetServices to get a list of all object names and then create connections to them.
Using NSNetServices is a little bit more complicated than DO. The API is asynchronous and sends delegate messages whenever it receives a service advertisement over the network. It is a very general API and can be used with custom protocols. iTunes, for example, uses it to advertise DAAP shares for shared playlists and iChat uses it to advertise serverless XMPP connections.
The advantage of DO is that you don't need to write any networking code yourself. With DO and NSNetServices, you can advertise an object to all machines on the network and they can get a reference to it and use it as if it were a local object. This means that you can write an application that works seamlessly with all instances running on the local network without having to write any networking code. The closest you come is NSNetServices, but it presents a very high-level interface.