views:

78

answers:

1

I'm trying to implement a binary protocol between a flash application and a Custom Java Server using TCP/IP sockets, the protocol's messages are of variable length, so my idea is to add a field indicating the number of bytes I have to read before parsing a complete message, something like this:

bytesToRead = socket.readInteger();
var bf:ByteArray;
socket.readBytes(bytesToRead);
parseMessage(bf);

So my question is: if while processing a message (supossing it is complete) other data arrives through the socket, are messages of type ProgressEvent.SOCKET_DATA queued so the number of times my handler is called is equal (at least in this case) to the number of messages arrived or should I read until all data the socket has available? or simpler: are in general messages for a handler queued in flash?

+2  A: 

The ProgreeEvent.SOCKET_DATA event is dispatched every time the socket receives data. Basically every time your Java server calls socket.write(); or socket.writeln(), you should receive the entire message in the ProgreeEvent.SOCKET_DATA unless you are of course you are sending partial messages.

Hope this answers your question.

Chris Gutierrez