Question: Hi, writing a Java TCP socket program consisting of a client and a server. I have finished the requirements for the client, but need help

Hi, writing a Java TCP socket program consisting of a client and a server. I have finished the requirements for the client, but need help with the server portion. I need to modify the code at the bottom so that the Local Server S (localhost):

  1. listens for and accepts the connection from C (the client) on port 11211
  2. receives and prints the message WEB SERVER= followed by Ws name sent by C
  3. prints the message IP ADDRESS= followed by Ws IP address
  4. prints the message SERVER START= followed by Ss local system time ST1
  5. uses the class HttpURLConnection to connect to the web server W on port 443
  6. receives Ws page from the web server W
  7. prints the message SERVER END= followed by Ss local system time ST2
  8. prints the message SERVER DELAY= followed by the value of ST=ST2-ST1 in milliseconds
  9. sends to C the page received from the web server W
  10. sends to C the value of ST

Additionally, the code should not have any threads, and System.exit() cannot be used. Here is the code that needs to be modified:

import java.io.*; import java.net.*; class TCPKRServer { public static void main(String argv[]) throws Exception { String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + ' '; outToClient.writeBytes(capitalizedSentence); } } }

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!