2013-12-23 51 views
0

以下是我的代碼。我一直在幾個論壇上討論如何解決這個問題。我的nodejs正在斷開連接並向我發送此警告消息。 warn: client not handshake client should reconnectSocket.io警告:客戶端不握手客戶端應重新連接

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});     

      } 

    });   

}); 
+0

可能重複的:http://stackoverflow.com/questions/9486254/node-js-and-socket-io-client-not- handshaken,客戶應重新連接 –

回答

0

使用此代碼在客戶端:

var socket = io.connect('http://domain.com:port', { 
     'connect timeout': 500, 
     'reconnect': true, 
     'reconnection delay': 500, 
     'reopen delay': 500, 
     'max reconnection attempts': 10 
    });