I have a service on Android that listens and responds to packets it receives via multicast.
This works most of the time, but unfortunately, I'm finding that every now and again it'll just stop receiving packets. The thread remains blocked on the call to MulticastSocket.receive(), but nothing comes out. I've been slowly trying to track down what triggers this, and I've discovered that turning the wireless off and on again, or changing wireless connection will do it.
In order to successfully continue to listen for my packets I need to close the MulticastSocket and recreate it again. However, I haven't found any way of doing this --- I don't appear to get any notification that something's happened: no intents, no Java exceptions, nothing. I would expect the receive to throw an IOException if the socket became invalid, but this appears not to be happening.
Can anyone offer any insight as to (a) what's actually going on, and (b) how to work around it? Right now my best guess is to continually destroy and recreate the socket every ten seconds or so, and that's just evil.