Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago