javascript - Send event to client, from server, and then disconnect the socket (from server) -
i want send event client, in socket.io, , after disconnect client. problem calling socket.emit() not emit anything... know, or stepped kind of problem?
my code this: - on server:
usercredentialscheck: function (socket, next, callback) { applogsys.info('check cookie!'); ..... var handshake = socket.request; ..... parsecookie(handshake, null, function (err, data) { sessionsrv.get(handshake, function (err, session) { if (err) { applogsys.error(err.message); next(new error(err.message)); } else { ...... socket.emit('na', 'error checking session! bye!'); socket.disconnect(); } }) }) };
on client:
appsocket.on('na', function(d){ console.log('error: '+d); console.log('now, redirect!'); //redirect! var delay = 1000; //your delay in milliseconds var url = '/'; settimeout(function(){ window.location = url; }, delay); });
thank you!
Comments
Post a Comment