0

My Android application stalls at s.receive(p) because it is not receiving any packets.

I have X-Plane sending packets of data to random port 49059 in the SAME IP address as the Android Tablet that I want to receive those packets. This is because they are running off the same connection. X-Plane uses ports 49000 to send packets and 49001 to receive packets.

I cannot figure out what is wrong. I can't use 3G on the Android tablet, and this is the only internet connection I can test on. Also, ALL internet and wifi permissions are enabled in the manifest. Any ideas? Here's the code:

byte[] bar = new byte[1024];
DatagramPacket p = new DatagramPacket(bar, bar.length);
DatagramSocket s = new DatagramSocket(49059);
s.setSoTimeout(30000);
s.receive(p);
datWooWoo
  • 843
  • 1
  • 12
  • 42

1 Answers1

0

If you have wireshark, try checking if the packets are being sent by the X-Plane.

Also, you say your "application freezes" which doesn't necessarily mean the packets aren't being received. I don't know what you are trying to do, but maybe you are performing the receive/send operation on the UI thread, which would cause the application to freeze.

Try putting a log after the s.receive(p) like below and check if it appears in the LogCat. Log.d("MYACT","Packet received");

Alabhya
  • 490
  • 1
  • 9
  • 16
  • The android tablet doesn't need to send packets back, so it is only receiving. Yes it is in the UI thread for now, just to make sure it works. It is not receiving the packets though, as I have already put a Log.d after s.receive(p) and it doesn't reach there. What I meant by "freezes" is that it stalls on the receive function. – datWooWoo May 24 '12 at 21:28
  • I meant ensure that the source of the packets is actually sending the packets. And is the buffer size for receiving the packet (1024 in your case) enough? Also, try a different port too,just in case. It would be helpful if you could clarify what you mean by "in the same IP" – Alabhya May 26 '12 at 05:37
  • Got it working, thank you for helping, Wireshark helped identify the problem (wrong IP). – datWooWoo May 29 '12 at 18:16