< Previous PageNext Page > Hide TOC

Using DNS Service Discovery in Windows

DNS Service Discovery was written with cross-platform compatibility in mind. Therefore, all of the DNS Service Discovery API calls that are valid in Mac OS X are also valid in Windows. The difference between the two platforms lies in how each handles run loops. The next two sections will explain what changes need to be made to write programs that take advantage of DNS Service Discovery in Windows. Before reading these sections, you’ll want to become familiar with the DNS Service Discovery API and Microsoft Foundation classes, if you are not already.

Contents:

Windows Graphical User Interfaces
Windows Command-Line Interfaces


Windows Graphical User Interfaces

To properly incorporate DNS Service Discovery in a Windows graphical user interface, use the WinSock API WSAAsyncSelect. WSAAsyncSelect integrates socket-based network events into the Windows message loop. To use this in your Windows code, you should first create and initialize a DNSServiceRef. Then, call the function WSAAsyncSelect to associate your DNSServiceRef’s socket with the Windows message loop. WSAAsyncSelect requires four arguments: a socket to your DNSServiceRef, a window to receive the message, a message to be sent when the event occurs, and a bitmask for the network events you are interested in. A simple example of this is provided below. In the example, you can see how to create a NULL DNSServiceRef, initialize that reference with DNSServiceBrowse, and then add it to the work loop with WSAAsyncSelect.

// create blank DNSServiceRef
e = new ServiceHandlerEntry;
...
// initialize the DNSServiceRef for browsing
err = DNSServiceBrowse( &e->ref, 0, 0, e->type, NULL, BrowseCallBack, e );
 
// add browsing to the work loop with WSAAsyncSelect
//  where m_hWnd is the window, WM_PRIVATE_SERVICE_EVENT is the message and
//  FD_READ and FD_CLOSE are bitmasks for reading and closing sockets
err = WSAAsyncSelect((SOCKET) DNSServiceRefSockFD(e->ref),
                    m_hWnd,
                    WM_PRIVATE_SERVICE_EVENT,
                    FD_READ|FD_CLOSE);

Windows Command-Line Interfaces

Creating a Windows command-line program using DNS Service Discovery is similar to creating one for Mac OS X. Windows, like Mac OS X, has support for the select system call. This function is used to determine when results are available from the DNS Service Discovery API functions. More information about using the select loop with DNS Service Discovery is available in “Registering and Terminating a Service,” “Browsing for Network Services,” and “Resolving the Current Address of a Service.”



< Previous PageNext Page > Hide TOC


© 2005 Apple Computer, Inc. All Rights Reserved. (Last updated: 2005-11-09)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.