I am working with UDP and DatagramSocket. I verified that the Receive
function clear all data more of setLength of DatagramPacket. My
packets have a variable len. I use first two bytes to understand the
len packet.
This is my code:
public void run() {
byte []buff = new byte[1024];
while(true){
ReadData(buff,2);
iSizePack = buff[1] & 0x000000FF;
iSizePack <<= 8;
iSizePack |= (buff[0] & 0x000000FF);
ReadData(buff, iSizePack);
}
}
private int ReadData(byte []byBuff, int iSize) throws IOException{
_datagram.setData(byBuff);
_datagram.setLength(iSize);
_socket.receive(_datagram);
int iRet = _datagram.getLength();
return iRet;
}
Seem that after first call to my ReadData to read the size of packet,
it read correctly the 2 bytes, but _socket.receive clear all remain
bytes, then to the next call of ReadData to read iSizePack, it read
the next datagram.
Can somebody confirm that ?
Is there a mode to maintain the data of datagram until of the datagram
is all read ?
thanks
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en