The following code should throw an exception based on whether a timeout was reached:
public boolean isAlive(int workerNum) throws Exception
{
System.out.println("Checking worker #" + workerNum + " from " +
getWorkerAddress(workerNum)
+ " at port " + getWorkerPort(workerNum));
DatagramPacket packet = new DatagramPacket("__ping__".getBytes(), "__ping__".length(),
getWorkerAddress(workerNum), getWorkerPort(workerNum));
socket.setSoTimeout(10000);
try {
System.out.println("Checking worker #" + workerNum);
socket.send(packet);
} catch (SocketTimeoutException e) {
e.printStackTrace();
return false;
}
return true;
}
I've tried in every possible scenario and I can guarantee that the packet is never even thrown as it is never recieved on the other side. Any idea why? Any help is greatly appreciated!