When I execute this code in android emulator
dataByte = new byte[1024];
ds = new DatagramSocket();
ds.setSoTimeout(3000);
dp = new DatagramPacket(dataByte, dataByte.length);
ds.connect(InetAddress.getByName(params[0]), Integer.valueOf(params[1]));
dp.setData("remdroid_test".getBytes());
ds.setSoTimeout(3000);
ds.receive(dp);
It results in not responding, what should i do?
Alternative suggestions on how to test a udp connection using Android are welcome.
If you are executing this code inside an Activity, then you are blocking the UI thread. If you block the UI for too long, then Android will force close your application.
One solution is to use an AsyncTask. The best option is probably to run it on a Thread from within a Service though.