If node server is down. How to get error handling

2019-02-21 03:05发布

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.

2条回答
Evening l夕情丶
2楼-- · 2019-02-21 03:31

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?

查看更多
SAY GOODBYE
3楼-- · 2019-02-21 03:38

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');
});
查看更多
登录 后发表回答