javascript - Reconnection in socket.io problem in `socket.on('message',function(){})` -
i have socket.io connection connect server , client,
work fine.
when try reconnect on disconnect server connected socket.on('message'
doesnt fired more.
checked server side pushing message.
please suggest me thing i out of ideas now.
sure problem on client side socket.on message
client side code
var socket = new io.socket('some host name',{port:80,remembertransport:true}); socket.on('connect', function(){ clearinterval(socketinterval); }); socket.on('message', function(obj) { alert("meg server"); }); socket.on('disconnect', function() { socketinterval=setinterval("socket.connect()",5000); }); socket.connect();
it appear "problem" on server side. server has 2 ways send messages client (emit , broadcast). if doing 1 one message, people use emit. assuming built chat server stores sessionids of client. works fine initial connection because server has correct sessionid, let's connection lost , reestablish connection, server tries send message client. if server stored initial sessionid, in array, , attempts use original sessionid emit message, fail because reconnection causes new sessionid created.
the solution in case remove previous sessionid array , add new sessionid upon reconnection.
Comments
Post a Comment