event SOCKET_DATA does not receive all messages in AS3
-
09-02-2021 - |
سؤال
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
Problem solved, I just had to open the port on my router.
نصائح أخرى
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 :)
لا تنتمي إلى StackOverflow