Android Udp Server Does Not Receive Packets
I have the following code to receive UDP packets: public class AsyncReceiveUdp2 extends AsyncTask { @Override protected Boolean doInBackground(String..
Solution 1:
put your receive inside a while(true) loop. When you receive a packet call an if (pkg_received){break;}... or whatever you want to do... The problem is that you are probably only be receiving one package and you are getting timeout before receiving it.
Code edited and not tested
while(true)
{
byte[] message = new byte[60*1024];
DatagramPacket recv_packet = new DatagramPacket(message, message.length);
try {
socket.receive(recv_packet);
} catch (IOException e) {
e.printStackTrace();
}
Log.d("UDP", "S: Receiving...listening on port " + recv_packet.getPort() );
String rec_str;
rec_str=newString(recv_packet.getData)
Log.d("PACKAGE LENGTH",Integer.toString(recv_packet.getLength()));
}
Post a Comment for "Android Udp Server Does Not Receive Packets"