2013-10-23 40 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