Java – Non-blocking datagram sockets?

Non-blocking datagram sockets?… here is a solution to the problem.

Non-blocking datagram sockets?

I’m currently working on a client app for Android that should do non-blocking reception of packets via UDP. Is there any way to set the DatagramSocket to be non-blocking on receive()?

Basically what I’m asking is how to set the MSG_DONTWAIT flag for DatagramSocket.

Solution

What you’re looking for is java.nio.channels.DatagramChannel and friend.

Related Problems and Solutions