• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps UDP DatagramSocket usage

dsgd47

Lurker
I am trying to port an application from Windows to Android that uses datagramsockets for communication. (C# to Java)

In the windows world, I created a messagereceived event listener that is automatically called when a UDP packet is received. The program continues to process data while it is waiting for a message to arrive.

In Android, there does not appear to be a corresponding event listener. All of the samples that I have found use loops to poll for the data and call the blocking datagramsocket.receive method to fetch the packet.

My program can't sit idle as it waits for the UDP packet, it needs to work even if the other end of the UDP system is down.

Can anyone direct me to a resource that can show me how to replicate this process in java on the Android?

Thanks,
Dan
 
The problem is that I don't know how to get the event trigger. In the Windows world, DatagramSockets allow you to trigger events when a packet is received. The Android version does not seem to have this feature. It appears that you have to perform a blocking call to read the data.

Maybe DatagramSockets is not the correct way to get the data. I need to send and receive UDP communications.

Thanks,
Dan
 
Back
Top Bottom