Zero Configuration Networking: The Definitive Guide
6.1. Working with Bonjour/Zeroconf
Before getting started, you will need to ensure that you have Bonjour/Zeroconf and the SDK installed on your machine. This section also contains a brief discussion of the different tasks involved in writing and running a Zeroconf application. 6.1.1. Installing Bonjour
A useful page to bookmark is the Apple Developer Connection page for Bonjour, http://developer.apple.com/bonjour/. This page contains links to software, documentation, sample code, and other useful resources. 6.1.1.1. Macintosh
Bonjour has been part of Mac OS X since the 10.2 Jaguar release. The portable, cross-platform "dns_sd.h" API was added in the 10.3 Panther release. The Java API was added in Panther Version 10.3.9 and is also available in 10.4 Tiger and later. The command-line tool described in this chapter is available in 10.4 and later and can be invoked from a terminal window using the command dns-sd. If you're running 10.3.x, you can use the substantially similar mDNS command, or you can build the dns-sd utility for yourself from the Darwin open source code and place it in /usr/bin. The developer tools for Mac OS X include the C, Carbon, Cocoa, and Java APIs for DNS-SD. 6.1.1.2. Windows
If your Windows machine didn't come from the manufacturer with Bonjour already installed, you can install it yourself. You can determine whether Bonjour is installed by running Internet Explorer and verifying whether the three-lobed, orange and gray Bonjour icon appears in the toolbar. If it does not, you can obtain the Bonjour for Windows installer from http://www.apple.com/bonjour/. If you're planning to write Bonjour software on Windows, you should also download the Bonjour SDK for Windows, containing header files, libraries, and sample code, from http://developer.apple.com/bonjour/. 6.1.1.3. Linux/Unix
Some Linux distributions already include some variant of Zeroconf. You can also download Apple's Darwin open source code for the mdnsd daemon, providing Multicast DNS and DNS Service Discovery (but not link-local addressing, which is a lower-level OS function), and build and install it yourself. This daemon will run on Linux, FreeBSD, NetBSD, OpenBSD, Solaris, and other POSIX-compatible platforms. 6.1.1.4. Other platforms
The Darwin open source repository for mDNSResponder also includes code for other platforms, such as Windows Mobile and the VxWorks embedded operating system used in specialized network devices such as printers and network cameras. On a simple, dedicated, single-function device, instead of having the mdnsd daemon running in the background serving multiple local clients, you would typically just run a single monolithic executable, mDNSResponderPosix, which directly advertises the services that the device provides. This code is licensed under the Apple Public Source License, and many hardware vendors include it in their products. 6.1.2. Understanding Zeroconf
When creating a Zeroconf-enabled application, it is important to understand what Zeroconf does and does not do. As an analogy, consider a GUI application for guessing a number between 1 and 100. The user enters a guess and is told whether the guess is correct, too high, or too low. The number of guesses is incremented and the user can guess again. The interface might look something like that shown in Figure 6-1. Figure 6-1. Interface for the guessing game
It helps to separate the code into three pieces.
There is an analogous separation in a Zeroconf application. In this case, it is important and helpful to think of the code in the following three pieces:
The strength and power of Zeroconf is that it performs a specific task and no more. The only design constraint imposed by DNS-SD is that it is for advertising services that run over IP; aside from that, you are free to design your protocol however you see fit. It can be text-based or binary. It can encode data by using XDR, ASN.1, XML, or any other encoding method. It can be client-server or peer-to-peer. It can be RPC- or message-oriented. DNS-SD can advertise and discover IP protocols as ancient as FTP, Telnet, and LPR printing; protocols as recent as iChat, SubEthaEdit, and AirTunes; and future protocols not yet conceived. The remainder of this chapter explores how to use the dns-sd command-line tool to experiment with DNS-SD yourself. |
Категории