Not receiving UDP Broadcast packets on Android [solved]

I have working JUCE code that receives UDP Broadcast packets on the Desktop, but it does not seem to work on an Android device. I am able to communicate with the device with a unicast packet, so I know basic communications is working.

Does anyone have any experience with this? Several discussions of Android/UDP broadcast reception indicated having to use a MulticastLock, but those are references to Java related code, not C. And per those posts, I hoped that possibly just adding <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"> to the manifest would do the trick, but no such luck.

@Don_Turner I know you are an audio guy, but maybe you know someone who could help me out?

Do you create the DatagramSocket object with “enableBroadcasting = true”? I use it for recognising different devices in a network and works well on Android, iOS, Linux etc.

Example code:

DatagramSocket socket(true);

String message = "broadcast!";
if (socket.waitUntilReady(false, 1000))
    socket.write("", 7766, message.getCharPointer(), message.length());

@MBO, thanks for replying. I am pretty sure I had the enableBroadcasting flag set to true. I’ll double check when I circle back to the issue. Your example shows sending a broadcast message, but I am needing to receive a broadcast message. Do you have an example of your receive code?

Yes. I have another thread for this task, so it looks like:

UDPReceiver::UDPReceiver(): Thread("UDPReceiver")


void UDPReceiver::run()
	if (!socket.bindToPort(7766))

	while (!threadShouldExit())
		if (socket.waitUntilReady(true, 0))
			char buf[1000];
			int cnt =, 1000, false);

			// do something...

@MBO, thanks again. my code matches what you have shown here, but it’s not working. I don’t know if it relates to the Android OS version (7.1.1, patched May 1st 2018), or the broadcast mask, which for ArtNet is just the last octet (ie., where in your send broadcast example you are doing all four ( Bottom line, you have verified that JUCE does the right thing for Android, and it should be working, so I’ll need to scratch my head for a bit on this.

Actually, the broadcast address shouldn’t be the issue, I just verified the devices configuration should allow for this:

wlan0     Link encap:UNSPEC
          inet addr:  Bcast:  Mask:

Dang, I hate it when things that should work do not work…

Whew! Got it working. I have a sender and a receiver using the same port, so I had to do setEnablePortReuse on both of them.

ok… um… kind of solved… the reception of the broadcast packet is very intermittent… :frowning:

Some time ago I had a similar issue, so I would suggest running a receiver application on different computers/devices to verify where is the problem. Another thing is that UDP messages are not guaranteed to arrive…

This same code works like a champ on multiple (Windows) desktop machines on this network. Next week my new Mac is coming in, so I will be verifying/testing on OSX, and also iOS.

An occasional dropped packet would be one thing, but the device is missing 5-100+ packets coming in at about ~8 second intervals…

Maybe try on another Android device if possible?
You can try to turn off Bluetooth on this Android device and check if it helps - on some devices it can be a problem, especially with Bluetooth/wifi combos.

Check also if you have dropouts with the global ( broadcast.