gpt4 book ai didi

node.js - Socket.IO服务器挂起

转载 作者:太空宇宙 更新时间:2023-11-03 22:42:52 25 4
gpt4 key购买 nike

我是 socket.io 的新手。所以我的 socket.io 服务器有时崩溃,出现以下错误

timers.js:103
if (!process.listeners('uncaughtException').length) throw e;
^
Error: socket hang up
at createHangUpError (http.js:1360:15)
at ServerResponse.OutgoingMessage._writeRaw (http.js:507:26)
at ServerResponse.OutgoingMessage._send (http.js:476:15)
at ServerResponse.OutgoingMessage.write (http.js:749:16)
at XHRPolling.doWrite (E:\sitesroot\0\node_modules\socket.io\lib\transports\
xhr-polling.js:67:17)
at XHRPolling.HTTPPolling.write (E:\sitesroot\0\node_modules\socket.io\lib\t
ransports\http-polling.js:132:8)
at XHRPolling.Transport.packet (E:\sitesroot\0\node_modules\socket.io\lib\tr
ansport.js:515:15)
at Object.<anonymous> (E:\sitesroot\0\node_modules\socket.io\lib\transports\
http-polling.js:79:12)
at Timer.list.ontimeout (timers.js:101:19)

它没有显示错误发生的位置或原因,因此非常确定它与我编写的代码无关。可能与运输有关?我对此了解不多。任何有关如何阻止其崩溃的建议将不胜感激。谢谢

最佳答案

问题正如@miktam 所说。要解决此问题,您需要在代码中添加错误监听器。将此代码添加到您的应用程序中:

//Error handler
process.on('uncaughtException', function (exception) {
// handle or ignore error
console.log(exception);
});

当出现错误时,它会console.log它而不是使其崩溃。我遇到了完全相同的问题,这解决了它。

关于node.js - Socket.IO服务器挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18657873/

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