If node server is down. How to get error handling on socket.io

荒凉一梦 提交于 2019-12-01 12:30:01

问题


How can i detect server status ?

var socket= io.connect('http://nodeserver.com:3000');

Here is my code. If nodeserver.com:3000 is down, how can i validate server down or up ?

I tried connect_failed, error events but doesn't work.


回答1:


have you tried doing it like this?

this.socket.on('connect_error', function (err) {
    //do something
});

in other words, use the connect_error instead of the connect_failed event?




回答2:


for checking "disconect" of a socket you can you this code :

io.socket.on('connect', function(){
  console.log('connected to server ...');

});

io.socket.on('disconnect', function(){
  console.log('Lost connection to server');
});


来源:https://stackoverflow.com/questions/28433532/if-node-server-is-down-how-to-get-error-handling-on-socket-io

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!