Search code examples
socket.ioconnectivity

Socket.io second server should connect when first one reconnect_failed


I got a scenario that i am implementing socket.io connectivity to push notifications to all clients,

    sockets = io.connect("http://localhost:3000");
       sockets.on("connection", function(socket){
            socket.on('connect',function(data){
             });
       socket.on('reconnect_failed',function(){
           console.log("reconnect_Failed");
               io.connect("http;//localhost:4000");
                 //Here i want to register a new socket when
                 // the first server is not able to reconnect
         });
      });

Please guide me to register when only first server is down. so that i can avoid the registering of second instance while running first server... Does this code helps. My Output is null not showing whether it is connected or not. First server is running fine.


Solution

  • You have a typo, http;//

    That should do :

    socket.on('reconnect_failed',function(){
               console.log("reconnect_Failed");
                   io.connect("http://localhost:4000");
                     //Here i want to register a new socket when
                     // the first server is not able to reconnect
             });
          });