I am creating a simple server that accepts a int
and returns the value received twice:
public class MyServer{
private static int port = 1234;
public static void main(String args[]){
try{
ServerSocket serversock=new ServerSocket(port);
while(true){
Socket socket=serversock.accept();
new Thread(new MyClass(socket)).start();
}
}catch(IOException e){}
}
}
class MyClass implements Runnable{
Socket socket;
public MyClass(Socket s){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){}
}
}
My question is about redesigning the code. Are there any weaknesses in the design? If yes, then what changes would make the code better?
catch(IOException e){}
At least pute.printStackTrace();
between the braces. \$\endgroup\$