socket.io: why socket.disconnect() on client side doesn't fire disconnect event on the server?
here’s my code:
client-side
var socket = io.connect('http://' + serverAddress ,{ reconnection: false, forceNew: true } );
socket.emit('monitorAddedNotify' , { video: sourceVideo , socketId: socket.id});
socket.on('disconnectThatSoc', function(){
socket.disconnect();
});
server-side:
io.on('connection', function (socket) {
console.log('a user connected');
socket.on('disconnect', function () {
console.log('user disconnected');
});
});
the socket.disconnect() method doesn’t work why?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 27 (4 by maintainers)
are you dumb? you are waiting for an emit on client but no emit on server. fuck out of here
That’s some real negative energy, Ehsan666x.
Maybe to manually disconnect the client, you can use a function with some emitting. I don’t know if this’ll help, but I think I got something… Maybe…
Client:
Server:
Sorry, but I probably left some holes in my code. I’m no professional. 🙁
I handled this problem this way. I’ve made an emit sender on client which is calling heartbeat on server.
I found this code function to call:
io.sockets.connected[socket.id].disconnect();Try to enter page and fast reload by pressing many times F5 button.
hahaha wow i can’t believe i was on this thread 4 years ago
This still happens. It doesn’t have to be F5/refresh. Opening a tab and closing it soon quickly at a certain stage, causes disconnect to not be triggered. It’s hard to reproduce because sockets are very fast, especially when running locally. I noticed opening the tab in the background and having other tabs open helped to reproduce the problem (locally). I think this is an important bug that should be addressed.