【问题标题】:event SOCKET_DATA does not receive all messages in AS3事件 SOCKET_DATA 没有收到 AS3 中的所有消息
【发布时间】:2011-10-13 18:38:33
【问题描述】:

我的 AS3 客户端程序在发送大量消息时没有收到发送给它的所有数据。我知道不是我的服务器导致了这个问题,因为所有消息都被正确接收和发送。我的 as3 客户端只是没有收到所有发送的数据。

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

你们有谁知道解决办法吗?

【问题讨论】:

    标签: sockets actionscript data-loss message-loop


    【解决方案1】:

    今天下午我也遇到了同样的问题。最后我提出了一个解决方案: 实际上,您必须像这样逐字节读取消息:

    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
            }
        }
    }
    

    希望对你有帮助:)

    【讨论】:

    • 我遇到了与 OP 相同的问题,这有所帮助,但我最终还是收到了数据并对其进行了删减(似乎在一种情况下我只收到了一半的数据。)跨度>
    【解决方案2】:

    问题解决了,我只需要打开路由器上的端口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-26
      • 2013-04-05
      • 2014-11-12
      • 2011-09-07
      • 2017-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多