SocketRocket崩溃了Node.js WebSocket

时间:2013-10-23 14:44:59

标签: ios node.js crash websocket socketrocket

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

我还写了一个使用SocketRocket连接上述服务器的iPhone应用程序。在applicationDidEnterBackground:,我在close上致电webSocket。并且,在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

为什么会这样?而且,我该如何解决它?

1 个答案:

答案 0 :(得分:3)

我昨天遇到了同样的错误,并且能够通过附加'error'事件处理程序

在Node.Js端修复它
wss.on('connection', function(connection) {
  connection.on('error', function(reason, code) {
    console.log('socket error: reason ' + reason + ', code ' + code);
  });
}

我将尝试在SocketRocket代码中找到导致该问题的原因,但现在可以使用