Answered step by step
Verified Expert Solution
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):
- listens for and accepts the connection from C (the client) on port 11211
- receives and prints the message WEB SERVER= followed by Ws name sent by C
- prints the message IP ADDRESS= followed by Ws IP address
- prints the message SERVER START= followed by Ss local system time ST1
- uses the class HttpURLConnection to connect to the web server W on port 443
- receives Ws page from the web server W
- prints the message SERVER END= followed by Ss local system time ST2
- prints the message SERVER DELAY= followed by the value of ST=ST2-ST1 in milliseconds
- sends to C the page received from the web server W
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started