tags:

views:

38

answers:

1

Hi All,

I'm porting an app that I've already going working on Windows to Android. The premmis is the same, the server is continually sreaming out data packets and the client reads them in.

The problem I have is that whilst the orginal app works just fine, the Android App connectes okay, but looses loads of packets - is there something I can simply change to fix this?

This is the crux of the code (just v simply read bytes from the stream):

private InputStream m_RDSInputStream;

...

for (int lBytesToRead = 0; lBytesToRead < (lNetworkCarrierSize + lBytesSentFromServer); >lBytesToRead++) { int lDataByte = m_RDSInputStream.read(); m_RDSInputDataBuffer[lBytesToRead] = (byte)lDataByte;

}

I've tried reading x bytes in one hit - but wind up with the same problem. I know the server and link are not the problem

Thanks for any advise

Mark

A: 

Not sure what's wrong. This works flawlessly for me.
What I do, is send the size of a packet as the first 4 bytes of the packet.
Then I read the packet in one go:

InputStream isr = sock.getInputStream();
byte plength[] = new byte[4];

while(1)
{
    isr.read(plength, 0, plength.length);
    int packet_size = (int)unsignedIntToLong(plength);
    int bytes_read = isr.read(buf, 0, packet_size);
}
Miguel Morales