0

Below is my code. I have been in several forums on how to fixed the issue. My nodejs is disconnecting and sending me this warn message. warn: client not handshake client should reconnect.

var onInterval = function() {
  countdown--;
  var data = {
      countdown : countdown,
      startTime : startTime,
      endTime : endTime,
 }
 if(countdown == 0){
      var endTime = currTimer();
      winnerBox = randomFromInterval(1,2);
      clearInterval(myInterval);

       setTimeout(function(){

              countdown = 30;
              myInterval = setInterval(onInterval, 1000);
       }, 500);


  }

  io.sockets.emit('timer', { result: data });

}        

var myInterval = setInterval(onInterval, 1000);

io.sockets.on('connection', function (socket){

    socket.on('addUsers', function (data, callback) {

          socket.username = data.username;
          var message;

          if (clients.hasOwnProperty(socket.id)){
              if (clients[socket.id].alias == data.alias && clients[socket.id].itemid ==  data.itemid && clients[socket.id].box == data.box) {
                    delete clients[socket.id];
                    io.sockets.emit('displayUsers', {users: data.alias, cancel : true});

              }else {
                    clients[socket.id].itemid = data.itemid;
                    clients[socket.id].box = data.box;
                    clients[socket.id].key_price = data.key_price;
                    clients[socket.id].alias = data.alias;
                    clients[socket.id].message = '2' ; 
                    clients[socket.id].username = data.username ;  
                    io.sockets.emit('displayUsers', {users: clients[socket.id], cancel : false});
              }



          }else {   
                  clients[socket.id] = {
                      username : data.username, 
                      userid : data.user_id,
                      alias : data.alias,
                      itemid : data.itemid,  
                      box : data.box, 
                      socket_id : socket.id,
                      key_price : data.key_price,
                      message :  '1',
            }

                io.sockets.emit('displayUsers', {users: clients[socket.id], cancel : false});                

          }

    });         

});
vinayr
  • 11,026
  • 3
  • 46
  • 42
user2981607
  • 27
  • 2
  • 9
  • Possible duplicate of: http://stackoverflow.com/questions/9486254/node-js-and-socket-io-client-not-handshaken-client-should-reconnect – Justin Wood Dec 23 '13 at 03:07

1 Answers1

-1

use this code on client side:

    var socket = io.connect('http://domain.com:port', {
        'connect timeout': 500,
        'reconnect': true,
        'reconnection delay': 500,
        'reopen delay': 500,
        'max reconnection attempts': 10
    });
himanshu yadav
  • 1,818
  • 2
  • 13
  • 5