The TimeClient sample application ("03 TimeClient.exe"), shown in Listing 3-2, tests the TimeService service. The source code and resource files for the application are in the 03-TimeClient directory on the companion CD. When you start the program, the dialog box in Figure 3-8 appears.
Figure 3-8. Initial dialog box in the TimeClient sample application
To see the client/server communication work, you must type the server name in the edit control at the top of the dialog box. If you are running the client and the server process on the same machine, type a period as the server name (as shown in Figure 3-8). When you click the Request Server's Time button, the client application calls CreateFile, which connects the client to the server, causing the server to wake up and process the client's request. If the server is not running, CreateFile fails and a message box similar to the one shown in Figure 3-9 appears.
Figure 3-9. Message box displayed by TimeClient when the TimeService service isn't running
If the service is up and running, CreateFile returns a valid handle, and the client waits for the time data to come across the pipe by placing a synchronous call to ReadFile. After the client has the data, the client's pipe handle is closed, the time from the server (which came across in universal time) is converted to the client's local time, and the initial dialog box is updated to look like Figure 3-10.
Figure 3-10. The updated dialog box for the TimeClient sample application
Listing 3-2. The TimeClient sample application
|