2013-10-23 37 views
1

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

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

这究竟是为什么?而且,我该如何解决它?

回答

3

我昨天遇到了同样的错误,并能够将其固定到Node.js的一侧通过连接“错误”的事件处理程序

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

我将尽力找到什么导致在SocketRocket代码,但现在它适用于

+0

你知道吗? – mauricioSanchez