I've created a library for sending and receiving UDP broadcasts using a WiFi network, and my code works fine, I tried it using a Nexus 5 and a Samsung Galaxy S2 and the communication works great, they both send and receive.
When I try my same code with a Moto G, the device can send packages to other phones, but can't receive anything. I can blame the Moto G because the code works great in other two devices and they both can receive the packages that the Moto G sends. I even tried two different Moto G, one stock and one rooted with specific firewall policies.
I tried using different ports, not many honestly, but I guess the problem is not there.
Any clues what could be wrong?
Android versions for each device: Nexus 5: 4.5 S2: 4.1.2 Moto G 1: 4.4.2 Moto G 2: 4.4.1 (not sure)
I'm targeting SDK 16. My code is here.
MulticastSocket
for receiving instead ofDatagramSocket
.(224.0.0.0 to 239.255.255.255
)Sender
Receiver
My Moto G (4.4.4) shows the same problem. Sending UDP-packets works, but receiving UDP-packets does not. I found several websites describing the same problem for several other vendors.
Workaround: I solved the problem for my Moto G, by using MulticastSocket (instead of DatagramSocket) with TTL=1 and IP=224.0.0.1.