-2

I have written an Android app that listen on UDP port 5150 to receive encoded audio stream from a device connected to same wifi router. However the call to receive() method is blocked indefinitely and does not receive any data.

int FRAME_SIZE = 480;
byte[] udpBuffer = new byte[FRAME_SIZE];
DatagramSocket socket;

socket = new DatagramSocket(5150);
datagramPacket = new DatagramPacket(udpBuffer, FRAME_SIZE);

System.out.println("Starting UDP listener");
for(;;){
        socket.receive(datagramPacket);
        System.out.println("receiving UDP data");
}

I have set the following permission

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>

What could be the reason not to receive any UDP data?

Jason Nanay
  • 115
  • 1
  • 12

1 Answers1

-1

The issue was due to the IP address returned by the device being in reverse order. As a result my device IP sent to server was incorrect making the server to send data to an incorrect destination. After fixing this I was able to receive data.

Thank you all for the support.

Jason Nanay
  • 115
  • 1
  • 12
  • What server? None mentioned in your question. Your question says the data is sent by a device, not a server. – user207421 Jul 03 '18 at 02:11