Answered step by step
Verified Expert Solution
Link Copied!

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

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 Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

=+116 How do you calculate the book value of an asset?

Answered: 1 week ago

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago