Skip to content

Reading socket data must respect message boundaries. #6

Open
@GoogleCodeExporter

Description

@GoogleCodeExporter
Sometimes the server sends more bytes than one message at once, i.e. the
next message or at least the first bytes of it.
This breaks class Bridge.as.


In Bridge.handleReceiveSocketData(), these lines:


__client.readBytes( __byteBuffer, __byteBuffer.length,
__client.bytesAvailable );


should be something like this:


var readActually : int = Math.min( __totalBytes - __byteBuffer.length,
__client.bytesAvailable );

__client.readBytes( __byteBuffer, __byteBuffer.length, readActually ); 


Assume two messages, one of length 3, one of length 4, e.g. bytes: 3 50 51
52 4 60 61 62 63

When the server sends one chunk of data, say "3 50 51 52 4",
Bridge will read all four bytes (as __client.bytesAvailable == 4).
which is wrong: The next call of handleReceiveSocketData()
will read "60 61 62 63" and therefore will wait for 60 bytes!







What is the expected output? What do you see instead?


Please use labels and text to provide additional information.

Original issue reported on code.google.com by [email protected] on 19 Aug 2009 at 7:15

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions