I want to disable one error message produces by a socket timeout, because it's filling my console (Linux, terminal).
The code:
public ThreadListenResponseQuery(DatagramSocket socket){
this.socket = socket;
try {
socket.setSoTimeout(1500);
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void run(){
System.out.println("Waiting for response...");
// Waiting for 60 seconds...
while(System.currentTimeMillis() < startTime + 60000){
socket.receive(receive_packet);
// .. Additional work
}
}
The program is waiting for 60 seconds to get any response. I am setting a timeout on the socket because the while
cycle is freezing out if no response message is coming.
Error:
java.net.SocketTimeoutException: Receive timed out at java.net.DualStackPlainDatagramSocketImpl.socketReceiveOrPeekData(Native Method) at java.net.DualStackPlainDatagramSocketImpl.receive0(Unknown Source) at java.net.AbstractPlainDatagramSocketImpl.receive(Unknown Source) at java.net.DatagramSocket.receive(Unknown Source) at thread.ThreadListenResponseQuery.run(ThreadListenResponseQuery.java:46) at java.lang.Thread.run(Unknown Source)