I am using a server-client based architecture with sockets in java on my localhost and I need to know how much it takes my localhost to send a response, any ideas on how I can measure that? (i am using 2 separate classes for listening to the keyboard and the server at the same time) This is my Clients main function:
public static void main(String[] args) throws IOException {
Socket socket = new Socket(SERVER_IP,SERVER_PORT);
ServerConnection connection = new ServerConnection(socket);
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(socket.getOutputStream(),true);
new Thread(connection).start();
while(true){
String command = keyboard.readLine();
if(command == "quit"){
break;
}
out.println(command);
}
socket.close();
System.exit(0);
}
This is my server connection class's run method where I listen to te server.
@Override
public void run() {
String res = null;
try {
while (true) {
res = in.readLine();
if (res==null) break;
System.out.println("Server>: " + res);
}
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
so in other words I am sending the request from one class and receiving it in another class.