Chapter 8. Using the Java APIs

Starting in Mac OS X 10.3.9, new APIs enable Java software to advertise and discover services on the network using Zeroconf’s DNS Service Discovery. The same Java DNS-SD APIs are also available in Bonjour for Windows, Bonjour for Linux, Solaris, *BSD, etc., enabling Java software to make use of Zeroconf’s DNS Service Discovery across a wide range of platforms, not just on Mac OS X. In this chapter, you will take a quick look through the APIs, see short examples of how to register, browse for, add TXT records to, and resolve services, and finally see a complete example of using Java DNS-SD in a tic-tac-toe game.

Understanding the APIs

The package exposes an abstract factory class, DNSSD, used to create the various types of DNSSDService objects, two classes used to manipulate DNS records, a collection of interfaces that are implemented as appropriate by client code to receive callback messages, and an exception:

  • Factory Class :

    • DNSSD

  • References to ongoing asynchronous operations :

    • DNSSDService

    • DNSSDRegistration

  • DNS Record Classes:

    • DNSRecord

    • TXTRecord

  • Callback Interface Classes , implemented by client:

    • BaseListener

    • RegisterListener

    • BrowseListener

    • ResolveListener

    • DomainListener

    • QueryListener

  • DNSSD Error Exception:

    • DNSSDException

The pattern for using the APIs will most often consist of calling a static method from the DNSSD factory class, passing in an instance of a class that implements the appropriate interface to receive callback ...

Get Zero Configuration Networking: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.