gpt4 book ai didi

ios - SocketRocket 导致 Node.js WebSocket 崩溃

转载 作者:太空宇宙 更新时间:2023-11-03 23:09:44 24 4
gpt4 key购买 nike

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

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

为什么会发生这种情况?还有,我该如何解决这个问题?

最佳答案

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

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

我将尝试在 SocketRocket 代码中查找导致此问题的原因,但目前它适用于

关于ios - SocketRocket 导致 Node.js WebSocket 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19544935/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com