New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
why socket.disconnect() on client side doesn't fire disconnect event on the server? #2297
Comments
As far as I tested, it works fine. How can we reproduce the issue? |
Try to enter page and fast reload by pressing many times F5 button. |
It works fine for me also. |
Which browser do you use? I'm using latest Firefox and when I fast reload bage "user disconnected" doesn't working 😞 |
I have the problem too. In these actions, disconnection, but it comes much later than was restarted browser. Browser: Chrome 55.0.2883.95 (64-bit) |
Hi @ventaquil. I'm the same trouble that the disconnect event not firing when holding F5. Have you got over this? |
@giathinh910 isn't the |
@darrachequesne My issue is the same as @ventaquil described above "Try to enter page and fast reload by pressing many times F5 button". Usually when you refresh a page socket connection will fire "disconnect" then "connect" again. I rely on these 2 events to update the numbers of online users. However if the page reloading fast enough, the "disconnect" won't fire, which cause some inexistent user socket id added. These unreal people will be removed after pingTimeout of course. Currently I change the way of saving socket id which will only show the online user, not the number of socket and the problem can be solved. |
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:
|
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. |
Having the same issue here. This is creating ghost games on my game server |
Maybe to manually disconnect the client, you can use a function with some emitting. Client: function ManualSocketDisconnect() {
socket.emit("manual-disconnection", socket.id);
socket.close();
console.log("Socket Closed. ");
} Server: io.on("connection", function(socket) {
console.log("User " + socket.id + " Connected. ");
socket.on("manual-disconnection", function(data) {
console.log("User Manually Disconnected. \n\tTheir ID: " + data);
});
}); Sorry, but I probably left some holes in my code. I'm no professional. 🙁 |
I am facing the same issue! Here is the situation, which will fire the event, and is encapsulated in I'll be comparing two events, which i will fire from
Now, Here we go:- These events are being fired:-
Following event wont fire.
The following event will be triggered.(just testing if normal message event emits)
No Luck Server:- //Following initializeChatSocket is called in app.js
Is this any issue with the browser or something else that i need to ask from stack-overflow community? |
@manjotsk I'm not sure if you've fixed it by now, but on your server side code you are listening for |
I have code that relies on the socket emitting the disconnect event to prevent duplicate ips-- users who reload my app quickly get blocked because the disconnect even never fires! |
|
@manjotsk What? |
and only use socket.once instead socket.on |
same here my
do not return the callback if anyone one knows tell me |
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. |
I wonder what |
Instead of |
Closed as unable to reproduce, please reopen if needed. |
hahaha wow i can't believe i was on this thread 4 years ago |
what was the solution? io.close() is an alias for io.disconnect() and didn't work |
@nandobfer could you please open a new issue with all necessary details? Thanks. |
here's my code:
client-side
server-side:
the socket.disconnect() method doesn't work why?
The text was updated successfully, but these errors were encountered: