admin管理员组文章数量:1278985
Is something like this possible?
socket.on('disconnect', function(){
console.log('disconnected...');
socket.connect();
socket.on('connect', function(){
console.log('...reconnected');
})
})
Is something like this possible?
socket.on('disconnect', function(){
console.log('disconnected...');
socket.connect();
socket.on('connect', function(){
console.log('...reconnected');
})
})
Share
Improve this question
edited May 5, 2011 at 14:22
davin
45.6k9 gold badges80 silver badges78 bronze badges
asked May 5, 2011 at 13:18
fancyfancy
51.5k64 gold badges157 silver badges230 bronze badges
2
- Most likely you already have an on "connect" event outside of disconnect so make sure not to duplicate the event. – Detect Commented May 5, 2011 at 15:28
- Yes, I do, just added it for the purpose of this question. Thanks – fancy Commented May 5, 2011 at 16:28
1 Answer
Reset to default 12Socket.io reconnects automatically (if you set the reconnect
option, although it defaults to true), so you don't really need to do that.
Furthermore, there is a reconnect
event which seems far more appropriate.
Also, set your event handlers independently, don't set the connect handler in the execution of the disconnect handler.
本文标签: javascriptSocketio reconnect on disconnectStack Overflow
版权声明:本文标题:javascript - Socket.io reconnect on disconnect? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741269588a2369028.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论