Create one or more of the following suites for the protocol:

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.





i.

Connectionless server;




Model the suite after the Echo*1 suite. The difference is that in the Client module, the ClientHelper’s method is invoked to send a single string containing a name to the server, receives a string back, display the string received, then exit.
```
public class NameClient1 {
public static void main(String[] args) {
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(is);
try {
System.out.println("Welcome to the Name client.\n" +
"What is the name of the server host?");
String hostName = br.readLine();
if (hostName.length() == 0) // if user did not enter a name
hostName = "localhost"; // use the default host name
System.out.println("What is the port number of the server host?");
String portNum = br.readLine();
if (portNum.length() == 0)
portNum = "1234"; // default port number
EchoClientHelper1 helper =
new EchoClientHelper1(hostName, portNum);
boolean done = false;
String message, names;
System.out.println("Enter a name");
message = br.readLine( );
names = helper.getNames( message);
System.out.println(name);
} // end try
catch (Exception ex) {
ex.printStackTrace( );
}
} //end main
} // end class
```

The server must maintain a string for accumulating the names. The service logic requires no change. The server class looks like this:
```
public class NameServer1 {
public static void main(String[] args) {
String names = ""; // string for accumulating the names
int serverPort = 1234; // default port
if (args.length == 1 )
serverPort = Integer.parseInt(args[0]);
try {
// instantiates a datagram socket for both sending
// and receiving data
MyServerDatagramSocket mySocket = new
MyServerDatagramSocket(serverPort);
System.out.println("Name server ready.");
while (true) { // forever loop
DatagramMessage request =
mySocket.receiveMessageAndSender();
System.out.println("Request received");
String message = (request.getMessage( )).trim( );
System.out.println("name received: "+ message);
names += message + "\n";
// Now send the names back to the requestor
mySocket.sendMessage(request.getAddress( ),
request.getPort( ), names);
} //end while
} // end try

```

Computer Science & Information Technology

You might also like to view...

GUI stands for

(A) graphical user interface. (B) graphing user introduction. (C) graphical unit interface. (D) graphical user input.

Computer Science & Information Technology

Which of the following statements best describes a packet filtering firewall?

A) It examines each packet against a set of criteria. B) It can keep track of the status of the connection. C) It works by examining the client application to determine if traffic is permitted. D) It authenticates the client before examining the application.

Computer Science & Information Technology

In the accompanying figure of a Microsoft Word 2016 document, which of the following boxes is pointing to the Bar Tab stop marker?? ?

A. ?Box A B. ?Box B C. ?Box C D. ?Box D

Computer Science & Information Technology

The ________ event is raised when a mouse button is pressed.

a) MousePress b) MouseClick c) MouseDown d) MouseButtonDown

Computer Science & Information Technology