Reputation: 73
I am working on a client-server project that sends/receives using UDP socket which handles packet drop and timeouts. Since the receive method is blocked every time the packet is lost (if timeout occurs), i need to find a way to kill the thread where the receive socket is blocked. The problem is, it is not throwing any exception so have no idea how to kill the thread.I want to terminate the thread so that i can restart again the next attempt.
Upvotes: 0
Views: 132
Reputation: 310893
need a way to kill the thread
No you don't.
You need a way to detect the timeout.
Set a read timeout, with setSoTimeout()
, and catch SocketTimeoutException
when it triggers.
Upvotes: 1