My Dart-VM application has a socket open to a remote server that is sending multiple variable length BINARY packets to me. The value of the first two bytes of each packet is the total length of that packet. It's possible, even likely the packet may not be complete or even some of the next packet's bytes are available at the moment I'm notified. As far as I've found, ALL the available bytes in the stream have already been read into a buffer before I'm notified of anything. Is there a way of "peeking" at the pending stream to read the first two bytes and then make sure all are available before reading JUST the expected quantity of bytes or do I have to do my own buffering and splitting/joining of multiple packets?
Here is the code I'm using:
ServerSocket.bind(InternetAddress.ANY_IP_V4, 8123).then
(
(ServerSocket server)
{
server.listen(handleSocket);
}
);
void handleSocket(Socket client){
client.listen((data){
int pkLen=data.length;
//By the time it gets to this line,
//data has already been read from the stream
//and may be incomplete or contain extra data
Thanks in advance,
John