Java Reference
In-Depth Information
There is no standard protocol for this type of application. Therefore, we
have to develop our own protocol. We decide to use a synchronous protocol,
because it is simpler to implement than an asynchronous one. To perform
any of the required operations the terminal software sends a request
message to the server and waits for the reply. The messages that constitute
the protocol are described in Table 14.1.
If a request succeeds, the reply message starts with the string OK followed
by a parameter that contains additional information specific to each request.
If the request fails, then the server's reply starts with the string ERROR
followed by a description of the cause of failure.
The acquisition of a product requires three interactions as shown in
Figure 14.13. Therefore six messages are required. The longest message is a
reply containing the name of the product, which can be 20 characters long;
the payload in this case is 25 bytes. According to Equation 14.2, the
maximum number of supported terminals for this protocol is 60.
Decision point
How do we introduce the data exchange protocol into the system?
server interaction through the protocol a modifi-
cation of the structure of the previous prototype is required. On the counter
terminal side the class LocalProxy is substituted by the class SocketProxy ,
shown on the left side of Figure 14.14. This class implements the
MarketProxy interface as well but, instead of invoking directly the Market
interface, exchanges messages according to the protocol described above.
On the central server side two new classes are required as shown on the
right side of Figure 14.14. The class MarketStub is the counterpart of the
SocketProxy as far as the communication protocol is concerned. This class
mediates, through the communication protocol, the access of the Socket
Proxy class to the Market interface. The class StubFactory accepts connec-
tions from the terminals; whenever a terminal establishes a connection a
new MarketStub object is created to handle the communication.
To implement the client
Table 14.1 Protocol messages
AUTH <employee code> <password>
OK <employee name>
Log in the employee; if successful
return the name of the employee
GET_CUSTOMER <customer code>
OK <customer name>
Set the current customer and
return the name
GET_NAME <product code>
OK <product name>
Get the name of a product
GET_PRICE <product code>
OK <product price>
Get the price of a product
BUY <product code> <quantity>
Buy a quantity of product
Terminate the transaction
Close the socket connection
Search WWH ::

Custom Search