Question: 4. Servers are supposed to run for a long time without stoppingtherefore, they must be designed to provide good service no matter what their clients

4. Servers are supposed to run for a long time without stoppingtherefore, they must be designed to provide good service no matter what their clients do. Examine the server TCPEchoServer.java and list anything you can think of that a client might do to cause it to give poor service to other clients. Suggest improvements to fix the problems that you find.

5. Based on your answers to Question 4, or more specifically, your answers to "Examine the server TCPEchoServer.java and list anything you can think of that a client might do to cause it to give poor service to other clients," and revise TCPEchoClient.java to implement such a client, which I call a bad client. Your bad client should attempt to cause the server to provide poor services, in at least 2 different ways. (5 points, 2.5 for each bad behavior)

6. Based on your answers to Question 4 and 5, or more specifically, your answers to "Suggest improvements to fix the problems that you find," revise TCPEchoServer.java to incorporate those improvements. You can call this improved server a bullet-proof server. (5 points, 2.5 for each improvement)

TCPEchoServer.java

4. Servers are supposed to run for a long time without stoppingtherefore,

TCPEchoClient.java

they must be designed to provide good service no matter what their

import java.net.* I/ for Socket, ServerSocket, and InetAddress 5 import java.io.*; /7 for IOException and Input/OutputStrearm 6 7 public class TCPEchoServer 9 private static final int BUFSIZE= 32; // Size of receive buffer 10 11e public static void main(String[I args) throws IOException 12 13 14 15 16 17 18 19 20 21 if (args.length !-1) // Test for correct # of Aras throw new IllegaLArgumentExceptionC" Parameter(s): "); int se rvPort = Integer.parseInt(args[0]); // Create a server socket to accept client connection requests ServerSocket servSock - new ServerSocket(servPort); int recvMsgSize; // Size of received message byte receiveBuf = new byte [BUFSIZf]; // Receive buffer 23 24 25 26 27 28 29 30 31 32 while (true) I/ Run forever, accepting and servicing connections socket c1ntSock = servSock.accept(); // Get client connection SocketAddress clientAddressclntSock.getRemoteSocketAddressO; System.out.println( Handling client at " +clientAddress); InputStream in = clntSock.getInputStream(); OutputStream out = clntSock.getOutputStream(); // Receive until client closes connection, indicated by -1 return while ((recvMsgSize-in.read(receiveBuf)) !- -1) 34 35 36 37 38 39 40 41 out.write(receiveBuf, 0, recvMsgSize); clntSock.closeO; // Close the socket. We are done with this client! NOT REACHED

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!