3

I'm making a multiplayer game with a node.js server with socket.io and a html5 canvas with a js file in it for client.

Now I have the socket.on('disconnect',function(){my code here}); on server side, but when a user closes the tab the client is running in it doesn't trigger any disconnect event in the server, but I need the server to notice when a user closes the tab.

How can I make the client trigger the event correctly when one closes the tab it's running in?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Wingblade
  • 9,585
  • 10
  • 35
  • 48

1 Answers1

2

I don't think, that it's possible. So I would suggest to have a timeout for each socket connection on the server to close it automatically. On the client side, you could send a "ping" to keep the connection open, when nothing happens. ;) How about that?

matths
  • 760
  • 9
  • 19