0
我目前正在DatagramSocket上發送一個DatagramPacket,我收到了很好..問題是我正在接收我發出的數據包。如果我打電話給接收兩次然後超時。是否有辦法忽略第一個數據包並接收第二個數據包。Android廣播UDP循環
這裏是我的代碼..
socket = new DatagramSocket(8001);
socket.setBroadcast(true);
socket.setReuseAddress(false);
DatagramPacket packet = new DatagramPacket(databytes, 7,
getBroadcastAddress(), 8001);
socket.send(packet);
String localAddress = socket.getLocalAddress().toString();
byte[] buf = new byte[1024];
DatagramPacket receivepacket = new DatagramPacket(buf, buf.length);
socket.setSoTimeout(5000);
String temp = "";
String delims = "[/]";
while(true)
{
try{
socket.receive(receivepacket);
temp = receivepacket.getAddress().toString();
temp = temp.split(delims)[0];
if(temp != localAddress)
{
}else
{
m_IPAddress = temp;
break;
}
}catch (SocketException e){
} catch (IOException e){
String temp1 = e.toString();
}
}
我很新的這..這將如何幫助我? – txagdev 2010-09-22 19:25:59
當我第二次調用接收時,它不應該接收第二個數據包嗎? – txagdev 2010-09-22 21:08:13
SecurityManager不接受來自廣播頻道的數據包會不會有問題? – txagdev 2010-09-22 21:09:10