event SOCKET_DATA does not receive all messages in AS3

2.3k views Asked by At

My AS3 client program does not receive all the data that was sent to it when sending a lot of messages. I do know its not my server causing this problem because all the messages are received and send correctly. My as3 client just does not receive all the data send.

    private function socketData(event:ProgressEvent):void {
       while(this.socket.bytesAvailable}
          var str:String = this.socket.readUTFBytes(this.socket.bytesAvailable);
          trace(str);
       }
    }

Does any of you know a solution?

2

There are 2 answers

0
inControl On BEST ANSWER

Problem solved, I just had to open the port on my router.

1
Karang On

I had the same issue this afternoon. Finally i came with a solution: In fact, you have to read the message byte by byte like so:

private function socketData (evt:ProgressEvent):void {
    var msg:String = ""; // create a buffer
    while (socket.bytesAvailable) { // while there is byte to read
        var byte:int = socket.readByte();
        if (byte==0) { // if we read the end byte
            trace(msg); // treat your message
            msg = ""; // free the buffer
        } else {
            msg += String.fromCharCode(byte); // else, we add the byte to our buffer
        }
    }
}

I hope this will help you :)