【问题标题】:SocketRocket crashes Node.js WebSocketSocketRocket 使 Node.js WebSocket 崩溃
【发布时间】:2013-11-01 22:06:16
【问题描述】:

我写了一个简单的Node.js WebSocket chat server。为了运行服务器,我使用了 foreman start 和仅包含以下行的 Procfilechat: npm start

我还编写了一个 iPhone 应用程序,它使用SocketRocket 连接到上述服务器。在applicationDidEnterBackground: 中,我在webSocket 上调用close。而且,在applicationWillEnterForeground: 中,我重新创建webSocket 并调用open

进入后台或前台时,iPhone 应用程序似乎会导致服务器崩溃并出现错误:

chat.1 | events.js:74
chat.1 |         throw TypeError('Uncaught, unspecified "error" event.');
chat.1 |               ^
chat.1 | TypeError: Uncaught, unspecified "error" event.
chat.1 |     at TypeError (<anonymous>)
chat.1 |     at WebSocket.EventEmitter.emit (events.js:74:15)
chat.1 |     at Receiver.self._receiver.onerror (~/Projects/Chat/node_modules/ws/lib/WebSocket.js:719:10)
chat.1 |     at Receiver.error (~/Projects/Chat/node_modules/ws/lib/Receiver.js:301:8)
chat.1 |     at Receiver.opcodes.8.finish (~/Projects/Chat/node_modules/ws/lib/Receiver.js:497:14)
chat.1 |     at Receiver.<anonymous> (~/Projects/Chat/node_modules/ws/lib/Receiver.js:478:33)
chat.1 |     at Receiver.add (~/Projects/Chat/node_modules/ws/lib/Receiver.js:93:24)
chat.1 |     at Socket.firstHandler (~/Projects/Chat/node_modules/ws/lib/WebSocket.js:678:22)
chat.1 |     at Socket.EventEmitter.emit (events.js:95:17)
chat.1 |     at Socket.<anonymous> (_stream_readable.js:746:14)
chat.1 | npm ERR! weird error 8
chat.1 | npm ERR! not ok code 0
chat.1 | exited with code 1
system | sending SIGTERM to all processes

为什么会这样?还有,我该如何解决?

【问题讨论】:

    标签: ios node.js crash websocket socketrocket


    【解决方案1】:

    我昨天遇到了同样的错误,并且能够通过附加“错误”事件处理程序在 Node.Js 端修复它

    wss.on('connection', function(connection) {
      connection.on('error', function(reason, code) {
        console.log('socket error: reason ' + reason + ', code ' + code);
      });
    }
    

    我会尝试在 SocketRocket 代码中找出导致该问题的原因,但现在它可以与

    【讨论】:

    • 你发现了吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-06
    相关资源
    最近更新 更多