Question: 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

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!