UDP Broadcast: Is Motorola Blocking Incoming Ports?

I created a library to send and receive UDP broadcasts using Wi-Fi network and my code works fine, I tried using Nexus 5 and Samsung Galaxy S2 and communication works fine, they both send and receive.

When I try to use the same code with Moto G , the device can send packets to other phones, but cannot receive . I can blame Moto G because the code works great on the other two devices and both of them can receive packets that Moto G sends out. I even tried two different Moto Gs, one stock and one with specific firewall policies.

I've tried using different ports, few are honest, but I think the problem is not there.

Any hints what might 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 am targeting SDK 16. My code is here .

+3


source to share


2 answers


My Moto G (4.4.4) shows the same problem. Sending UDP packets works, but receiving UDP packets fails. I found several sites 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.

+2


source


  • Use MulticastSocket

    for reception instead of DatagramSocket

    .
  • Send a broadcast message to a multicast address (224.0.0.0 to 239.255.255.255

    )

Sender

final String ip = "224.0.0.3";
final int port = 8091;
DatagramSocket socket = new DatagramSocket();
DatagramPacket packet = new DatagramPacket(msg,msg.length, InetAddress.getByName(ip),port);
socket.send(packet);

      



Receiver

MulticastSocket socket = new MulticastSocket(8091);
socket.joinGroup(InetAddress.getByName("224.0.0.3"));
byte[] data = new byte[4096];
while(!stop){
    DatagramPacket packet = new DatagramPacket(data,data.length);
    socket.receive(packet);
}

      

+1


source







All Articles