Modify the Building Services server so that it accepts a new request action, BOOKINGSONDATE. When such a request is received it should ignore the room, and instead retrieve the bookings for the given date. If there are no bookings the server should send an error reply. Otherwise, it should send as its reply not a single room string, but rather a string containing comma-space-separated room numbers as shown in Figure 18.4.

Modify the Building Services client so that it has a Bookings on Date? button, connected to a method that issues a suitable request. The client's read-Response() method will need to be modified slightly so that it can read the server's response to the new request.

The modifications necessary to provide "bookings on date" are quite straightforward. For a bit more challenge, modify the Building Services server to accept another new request action, BOOKINGSFORROOM. When one of these requests

Figure 18.4 Building Services—bookings on date

is received it should ignore the date, and instead iterate over all the bookings, accumulating a list of the dates for which the given room is booked. If there are no bookings, it should return an error reply. Otherwise, instead of using the sendReply() method, it should send its own byte array with its length, the action, the room string, and then a 32-bit integer containing the number of dates in the list, followed by each of the dates. Since the dates are stored as datetime.date objects, they must be converted to QDates to stream them into the QByteArray.

Figure 18.5 Building Services—bookings for room

The Building Services client must be modified to provide a Bookings for Room? button, connected to a method that issues a suitable request. The client's readResponse() method will need to be modified so that if a BOOKINGSFORROOM response is received, it reads in the dates and creates a suitable string for display in the client user interface, as shown in Figure 18.5.

The modifications to the server can be done by adding about 30 lines, and to the client by adding about 40 lines. However, the BOOKINGSFORROOM request/ response does require some care.

Solutions are provided in chap18/buildingservicesserver_ans.pyw and chap18/ buildingservicesclient_ans.pyw.

This page intentionally left blank

Creating a Threaded Server

Creating and Managing Secondary Threads

Implementing a Secondary Thread

Was this article helpful?

0 0
Tube Traffic Ninja

Tube Traffic Ninja

Discover How You Can Quickly And Easily Dominate Google and YouTube... With Simple Cash Generating Videos. Did you know that YouTube is the second largest search website on the entire Internet? YouTube gets more daily searches than Bing and Yahoo. In fact, there is only one search engine that gets more action.

Get My Free Ebook

Post a comment