Question: Language java QUESTION 4 (a) The code of a simple server is shown below. It offers the trivial service of accepting an integer value from


Language java
QUESTION 4 (a) 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 void main(String args[]X tryl ServerSocket serversock = new Server Socket(port); while(true) { Socket socket = serversock.accept(); new Thread(new Double(socket)).start(): } } catch (IOException e) 3 class Double implements Runnable{ Socket socket; public Double(Socket sy socket = s:} public void run try{ DataInputStream in = new DataInputStream(socket.getInputStream(); 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
Get step-by-step solutions from verified subject matter experts
