flash - Flex 4.6增加套接字接收缓冲区的大小

标签 flash apache-flex sockets flex4.5 flex4.6

我在套接字上遇到问题,正在发送的数据在客户端(Flash/Flex)上被截断。我的服务器发送的数据已满并且完好无损,但是在触发一个说要读取数据的事件之前,闪存不会等待适当的时间。这导致数据无法完全读取,并且(因此)在此之后我无法从中解析出对象。我们正在探索将对象分割成较小的块的可能性,但是我们的想法是使它尽可能轻巧,因此我们宁愿让它按应有的方式工作而不是在临时解决方案中打补丁。

我不确定是否将其称为接收“缓冲区”是否正确,因为有些计算机能够接收所有数据,而另一些计算机却将其截断(这意味着缓冲区足够,但是闪存没有等待无论出于何种原因,都可以安排适当的时间来安排 Activity )...如果有人有任何想法,我将不胜感激!

最佳答案

没有看到实现代码,听起来好像可用字节数或未计入总字节数。

这是我使用过的实现:

package
{
    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.events.IOErrorEvent;
    import flash.events.ProgressEvent;
    import flash.events.SecurityErrorEvent;
    import flash.net.Socket;

    public class WebRequestService extends EventDispatcher
    {

        //------------------------------
        //  model
        //------------------------------

        protected var hostname:String;

        protected var port:uint;

        public var requestMessage:String;

        public var responseMessage:String;

        private var _socket:Socket;


        //------------------------------
        //  lifecycle
        //------------------------------

        public function WebRequestService(hostname:String, port:uint, requestMessage:String)
        {
            this.hostname = hostname;
            this.port = port;
            this.requestMessage = requestMessage;

            _socket = new Socket();
            _socket.addEventListener(Event.CONNECT, socketConnectHandler);
            _socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
            _socket.addEventListener(Event.CLOSE, socketCloseHandler);
            _socket.addEventListener(IOErrorEvent.IO_ERROR, socketErrorHandler);
            _socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, socketSecurityErrorHandler);

            _socket.connect(hostname, port);
        }

        protected function socketConnectHandler(event:Event):void
        {
            responseMessage = "";
            _socket.writeUTFBytes(requestMessage);
            _socket.flush();
        }

        protected function socketDataHandler(event:ProgressEvent):void
        {
            while (_socket.bytesAvailable > 4)
            {
                responseMessage += _socket.readUTFBytes(_socket.bytesAvailable);
            }
        }

        protected function socketCloseHandler(event:Event):void
        {
            dispose();
        }

        protected function socketErrorHandler(event:IOErrorEvent):void
        {
            trace("socket error.");
        }

        protected function socketSecurityErrorHandler(event:SecurityErrorEvent):void
        {
            trace("socket security error.");
        }

        public function dispose():void
        {
            if (!_socket)
                return;

            if (_socket.connected)
                _socket.close();

            _socket.removeEventListener(Event.CONNECT, socketConnectHandler);
            _socket.removeEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
            _socket.removeEventListener(Event.CLOSE, socketCloseHandler);
            _socket.removeEventListener(IOErrorEvent.IO_ERROR, socketErrorHandler);
            _socket.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, socketSecurityErrorHandler);
        }

    }
}

关于flash - Flex 4.6增加套接字接收缓冲区的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10033433/

相关文章:

flash 播放器在尝试进入全屏模式 android 4.0 时崩溃

apache-flex - 在 Flex 应用程序中处理英文和中文的最佳方式是什么?

apache-flex - 如何在 Actionscript 中以编程方式将函数绑定(bind)到组件?

c - OpenSSL DTLS 连接从未建立

sockets - 用于身份验证的 chrome 应用程序客户端证书

flash - Flash 播放器可以使用的内存量是否有限制?

apache-flex - 如何从同时播放的所有声音中获取声音数据? ( ActionScript 闪烁)

html - 在 Actionscript 3 项目中显示 HTML

android - Adobe Flex Mobile 错误 1144 : Interface method initialize in namespace mx. core:IUIComponent is implemented with an incompatible signature

Python:在套接字监听连接时显示消息 'Waiting for player...'