SocketRocket崩溃Node.js WebSocket

我写了一个简单的Node.js WebSocket聊天服务器 。 要运行服务器,我正在使用一个只包含以下行的Procfileforeman start chat: npm start

我还写了一个使用SocketRocket连接到上述服务器的iPhone应用程序。 在applicationDidEnterBackground: ,我在webSocket上调用close 。 而且,在applicationWillEnterForeground: ,我重新创build了webSocketopen

当进入后台或前台时,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 

为什么发生这种情况? 而且,我该如何解决?

       

网上收集的解决方案 "SocketRocket崩溃Node.js WebSocket"

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

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

我将尝试在SocketRocket代码中find导致这种情况的原因,但现在它可以工作