Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4. Servers are supposed to run for a long time without stopping—therefore, they

ID: 3602822 • Letter: 4

Question

4. Servers are supposed to run for a long time without stopping—therefore, 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

TCPEchoClient.java

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

Explanation / Answer

#include <stdio.h>

int main()
{
    printf("Hello, World! I have created a dynamic 2D-array of 20x30 integers! ");
    int i,j,k,arr[20][30];
    k = 0;
    for(i=0 ; i<20 ; i++)
    {
        k = i;
        for(j=0 ; j<30 ; j++)
        {
            arr[i][j] = k;
            printf("%d ",k);
            k++;
        }
        printf(" ");
    }

    return 0;
}

                   =============>     OUTPUT      <=================

  

Hello, World! I have created a dynamic 2D-array of 20x30 integers!
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote