Bonjour Service Discovery Sample
Purpose
This sample demonstrates how to use ZeroConf service discovery mechanism for
both publishing and discovering services on the network.
Prerequisites
Bonjour for Windows is required to run this sample. It can be downloaded free of
charge from the Apple's website
http://support.apple.com/downloads/Bonjour_for_Windows.
How it works
First, the service have to be made discoverable. To make a service discoverable
it is necessary to do two things:
- Place and configure TROZeroConfRegistration component on the server's main
form.
- Call SetZeroConfDetails procedure in the service implementation unit's
initialization section.
The TROZeroConfBrowser component is used to discover available services on
the network. Discovery process is performed in the background and corresponding
events are being fired. When application is notified about new service available
it have to start resolve procedure to obtain host name (address) and port number
where to connect to. After hast name and port are obtained, the application can
construct target URL and connect to the server as ususal.
Examine the code
- See the how the TROZeroConfRegistration component is configured on the
server's main form.
- See how the SetZeroConfDetails procedure is being called in the
service implementation unit. Notice how service type is specified there.
- See the how the TROZeroConfBrowser component is configured on the client
side.
- Examine TClientForm.ROZeroConfBrowserServiceAdded and
TClientForm.ROZeroConfBrowserServiceRemoved event handler to see how the client
application responds to service availability change. Notice that these handlers
are called in the thread other than GUI main. So special processing is required to
interact with GUI components. In this sample main thread invokation is
implemented usning custom windows messages. Message parameters lParam and wParam
contain pointer to the procedure to be called and pointer to the procedure's
parameter.
- Examine TClientForm.btUseServiceClick to see how TargetURL is constructed.
Getting started
- Build the sample.
- Start the server application. Server's responce string can be changed.
Start the server with the 'Start server' button.
- Start the client application and see how server is discovered.
- Click 'Use service' button to communicate with the server.
- Try to run several servers on several machines or local host. See how
services list changes when servers are being
started and stopped. Select discovered services from the list and invoke
different remote services.