简体   繁体   English

SocketRocket崩溃了Node.js WebSocket

[英]SocketRocket crashes Node.js WebSocket

I wrote a simple Node.js WebSocket chat server . 我写了一个简单的Node.js WebSocket聊天服务器 To run the server, I'm using foreman start with a Procfile that merely contains the line: chat: npm start . 为了运行服务器,我正在使用foreman start一个仅包含行的Procfilechat: npm start

I also wrote an iPhone app that uses SocketRocket to connect to the aforementioned server. 我还写了一个使用SocketRocket连接上述服务器的iPhone应用程序。 In applicationDidEnterBackground: , I call close on webSocket . applicationDidEnterBackground: ,我在webSocket上调用close And, In applicationWillEnterForeground: , I recreate webSocket and call open . 并且,在applicationWillEnterForeground: ,我重新创建webSocket并调用open

When entering the background or foreground, the iPhone app seems to crash the server with the error: 当进入后台或前台时,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

Why is this happening? 为什么会这样? And, how do I fix it? 而且,我该如何解决?

I encountered same error yesterday, and was able to fix it on Node.Js side by attaching 'error' event handler 我昨天遇到了同样的错误,并且能够通过附加'error'事件处理程序在Node.Js端修复它

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

I will try to find what's causing that in SocketRocket code, but for now it works with 我将尝试在SocketRocket代码中找到导致该问题的原因,但现在它可以使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM