Answered step by step
Verified Expert Solution
Question
1 Approved Answer
IN JAVA The code of a simple server is shown below. It offers the trivial service of accepting an integer value from a client and
IN JAVA
The code of a simple server is shown below. It offers the trivial service of accepting an integer value from a client and returning twice the value received. Explain the weakness in the design of the server and re-write it in light of your critique.
import java.util*;
import java.net*;
class DoubleServer{
private static int port = 1234;
public static main(String args[]){
try{
ServerSocket serversock = new ServerSocket(port);
while(true){
Socket socket = serversock.accept();
new Thread(new Double(socket)).start();
}
}catch(IOException e) {}
}
}
class Double implements Runnable{
Socket socket;
public Double(Socket s){socket = s;}
public void run(){
try{
DataInputStream in = new DataInputStream(socket.getIntputStream());
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
int x = in.readInt();
out.write(2*x);
socket.close();
}
catch(IOException e) {}
}
}
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