How can i handle Close event in Socket.io?

前端 未结 2 1994
醉话见心
醉话见心 2020-12-08 11:35

I\'m making simple online game which based on Web. the game uses Socket.io for netwoking each other. but I encountered the problem.

think about following situation

2条回答
  •  庸人自扰
    2020-12-08 12:18

    Update: I created a blog post for this solution. Any feedback is welcome!

    I recommend using the 'sync disconnect on unload' option for Socket IO. I was having similar problems, and this really helped me out.

    On the client:

    var socket = io.connect(, {
    'sync disconnect on unload': true });
    

    No need to wire in any unload or beforeunload events. Tried this out in several browsers, and its worked perfectly so far.

提交回复
热议问题