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);
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");