【问题标题】:Frequent disconnects with XHR-Polling, Socket.io and Titanium与 XHR-Polling、Socket.io 和 Titanium 频繁断开连接
【发布时间】:2012-02-10 03:42:59
【问题描述】:

我通过https://github.com/nowelium/socket.io-titanium 在 Titanium 框架上使用 Socket.io。到目前为止,该“端口”仅支持 XHR 轮询传输。过去,我在使用 Websocket 传输的 Socket.io 方面取得了成功。

我现在遇到的问题是,我的套接字连接似乎每 10 秒“断开”一次,持续几秒钟。这意味着聊天消息被丢弃等。这是 XHR 轮询的预期行为 - 我是否需要实施队列系统 - 或者有什么方法可以解决这个问题?

   debug - setting poll timeoutdebug - discarding transport
   debug - cleared close timeout for client 407473253144647189
   debug - clearing poll timeout
   info  - transport end
   debug - set close timeout for client 407473253144647189
   debug - cleared close timeout for client 407473253144647189
   debug - discarding transport
   debug - client authorized
   info  - handshake authorized 4149191422068834219
   debug - setting request GET /socket.io/1/xhr-polling/4149191422068834219?t=Thu%20Jan%2012%202012%2022%3A37%3A47%20GMT-0800%20%28PST%29
   debug - setting poll timeout
   debug - client authorized for 
   debug - clearing poll timeout
   debug - xhr-polling writing 1::
   debug - set close timeout for client 4149191422068834219
Connection
   debug - setting request GET /socket.io/1/xhr-polling/4149191422068834219?t=Thu%20Jan%2012%202012%2022%3A37%3A47%20GMT-0800%20%28PST%29
   debug - setting poll timeout
   debug - discarding transport
   debug - cleared close timeout for client 4149191422068834219
Last login: Fri Jan 13 00:04:14 on ttys003

【问题讨论】:

  • 你在什么平台上运行这个?

标签: xmlhttprequest titanium socket.io


【解决方案1】:

为什么不在 Web 视图中加载 socket.io.js 并通过 Ti.App.fireEvent / addEventListener 泵送事件?这为您提供了没有轮询限制的 WebSockets。

<html>
<head>
    <script src="http://63.10.10.123:1337/socket.io/socket.io.js"></script>
    <script>
        var socket = io.connect('http://63.10.10.123:1337');
        socket.on('onSomething', function (data) {
            Ti.App.fireEvent('onSomething', data);
        });
        Ti.App.addEventListener('emitSomething', function (data) {
            socket.emit('emitSomething', data);
        });
    </script>
</head>
<body>
</body>
</html>

编辑:我想指出我是在一个项目中这样做的,它在 iOS 上非常一致地使我的应用程序崩溃。我环顾四周,即使没有使用 Titanium,其他开发人员也遇到了这个问题。我不建议采用这种方法,或者至少不建议对其进行彻底的测试(尤其是后台和恢复应用程序)。相反,我使用 Appcelerator 的 TCP 套接字和我自己的轻协议来将数据从客户端流式传输到服务器以及从服务器到客户端。

【讨论】:

    猜你喜欢
    • 2013-08-01
    • 2013-04-06
    • 1970-01-01
    • 2014-03-08
    • 1970-01-01
    • 2013-04-03
    • 2016-10-17
    • 2012-11-30
    • 1970-01-01
    相关资源
    最近更新 更多