The server is a console application project. It includes the same implementations of the SubscriberAccount and SubscriberInfo classes as the subscriber (see
Listing 2 and
Listing 3). Because the primary focus of this article is on the mobile device, I'll discuss the host code only in general terms, but you can
download the sample code to explore further.
 | |
Figure 4. The Host Project: The Serializable classes and the generated stub code are shared between the host and the subscriber projects. |
The file
ChatHost.cs (see
Listing 6) contains the host's
main() method, which instantiates a ChatHost object and then calls the method
runHost(). This method, like the client code, creates a new ORB and registers its services with the MiddCor Name Service.
The class HostImpl maintains the list of subscribers and contains the implementations of the exposed methods
signOn(),
signOff(), and
sendMessage(). The latter calls the private method
distributeMessage() that iterates through the list of subscribers and calls
displayMessage() for each one.
 | |
Figure 5. The Smartphone Emulator: The emulator is not the tool of choice to test a distributed application because it does not support callbacks. |
|
The
signOn() method calls
createSubscriberInfoList() and creates an instance of the
SubscriberInfo[] array of subscribers for each new subscriber. It calls the method
querySubscriberInfo() added to SubscriberAccount on the host to spawn a SubscriberInfo instance.
Deploy and Test
The host executable requires the Name Service (
MCns.exe) to be running. You can test the subscriber client without a mobile device; however, to run the client in debug mode, you must either deploy it to a physical device or to the SmartPhone 2003 emulator. Visual Studio will prompt you for a deployment target whenever you start the debugger. Note that the emulator has some limitations. For instance, it does not support the callback functionality, which means that the
displayMessage() method will not work and will eventually time out.
With this restriction in mind, use the following steps to test the application:
- Start the MiddCor Name Service (MCns.exe)
- Start the host executable (DotNetServer.exe)
- Start the subscriber executable (DotNetServer.exe)
- Open the subscriber configuration dialog and provide the correct server IP address, your screen name and your hobby
- Save your changes
- Sign on to the host