im making a basic packet reciever similar to Wireshark, i tried to make a loop in which if a key is pressed, another method is called, as in the code. But my problem is that when i try to enter any method, i need to press the key and enter so fast, if not the loop makes an iteration and the key`s method isnt called. Excuse me if i made any mistake writing English.
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(reader);
while (true) {
try {
if (in.ready()) {
s = in.readLine().toLowerCase();
if (s.equals("f")) {
break;
} else if (s.equals("b")) {
pa.borrarTabla();
System.out.println("Tabla ARP borrada correctamente");
} else if (s.equals("t")) {
paqARP.mostrarTablaARP(pa.getTablaArp());
} else if (s.equals("m")) {
cc.mostrarConf(pa);
} else if (s.equals("r")) {
em.enviarRangoARP();
} else if (s.equals("c")) {
em.petgwydst();
} else if (s.equals("i")) {
paqicmp.enviarSolicitud(em);
}
}
} catch (IOException ex) {
System.out.println("FALLO");
}
pa.setTablaArp(re.ejecutar(pa.getTablaArp(), em));
try {
Thread.sleep(20);
} catch (InterruptedException ex) {
}
}