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

后端 未结 2 2041
不知归路
不知归路 2021-01-07 07:41

How can i detect server status ?

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

Here is my code. If nodeserver.com:3000

相关标签:
2条回答
  • 2021-01-07 08:28

    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?

    0 讨论(0)
  • 2021-01-07 08:28

    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');
    });
    
    0 讨论(0)
提交回复
热议问题