Socket.IO服务器挂断 [英] Socket.IO server hangs up

查看:207
本文介绍了Socket.IO服务器挂断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to socket.io. So my socket.io server sometimws crashes giving this below error

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)

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

It doesnt show where or why the error is happening so pretty sure its nothing to do with the code i have written. Could be something with the transports? I dont have much knowledge on it. Any suggestions on how to stop it from crashing would be highly appreciated. Thanks

推荐答案

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

The problem is as @miktam stated. To fix this you need to add an error listener to your code. Add this code to your application:

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

一旦发生错误,它将console.log它而不是使其崩溃.我遇到了完全相同的问题,并已解决.

When ever there is an error it will console.log it instead of crashing it. I had the exact same problem and this fixed it.

这篇关于Socket.IO服务器挂断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆