protected String doInBackground(String... f_url) {
int count;
byte [] ip_bytes = new byte[] {(byte)192,(byte)168,(byte)1,(byte)100};
try {
InetAddress address = InetAddress.getByAddress(ip_bytes );
byte buffer[] = new byte[2000];
DatagramPacket p = new DatagramPacket(buffer, buffer.length, address, port);
try {
DatagramSocket ds = new DatagramSocket(port);
Log.d("..........","Perfect Binding .... Waiting for Data");
ds.receive(p);
publishProgress(""+p);
Thread.sleep(100);
Log.d("","Received :) ");
} catch(Exception e)
{
e.printStackTrace();
}
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
.................................... This is code for receiving UDP packet in Async Backgroung Process, But am not getting a single packet ... what is wrong in my code ?? How i can overcome this problem ?
对于接收来说,您不需要在DatagramPacket中指定ip和端口。
DatagramPacket p = new DatagramPacket(buffer, buffer.length);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.