Connection-oriented, concurrent server.
Using the three-tier software architecture presented in this chapter, design and implement a client-server suite for the following protocol (it is not a well-known service): Each client sends to the server a name. The server accumulates the names received from successive clients (by appending each, with a linefeed (‘
’), to a static string). Upon receiving a name, the server sends the names that it has collected to the client. The figure below illustrates the sequence diagram of a session of the protocol.
Model the suites after Echo*3.java.
A static String, names, in the Thread class can be used for holding the names.
A synchronized method provides mutual protection to the names string.
```
class NameServerThread implements Runnable {
static String names;
MyStreamSocket myDataSocket;
NameServerThread(MyStreamSocket myDataSocket) {
this.myDataSocket = myDataSocket;
}
public void run( ) {
boolean done = false;
String newName;
try {
newName = myDataSocket.receiveMessage( );
updateNames(newName);
// Now send the names to the requestor
myDataSocket.sendMessage(names);
myDataSocket.close( );
}// end try
catch (Exception ex) {
System.out.println("Exception caught in thread: " + ex);
}
} //end run
private synchronized void updateNames(String newName ){
names += newName + "\n";
} //end updateNames
} //end class
```
You might also like to view...
Answer the following statements true (T) or false (F)
1) Design patterns are restricted to particular programming languages, of which C++ is one. 2) UML is graphical language for designing programs. 3) UML requires that the programmer understand every detail and dark corner of C++ to be useful. 4) A pattern is a design principle that solves a problem that occurs over and over.
In a serial interface, what is the difference between a status of down and a status of administratively down?
What will be an ideal response?
To create a table using the view that features table fields and properties, use the ________ view
Fill in the blank(s) with correct word
On a movable-head system, the time it takes to position the head at the track is known as __________.
Fill in the blank(s) with the appropriate word(s).