The right way for a client to reconnect after the server does a socket.disconnect( true )
Problem
Server: node + socket.io [code block] Client: html/js + socket.io 1.4.5 [code block] The above is simplified but that is the basis. Reconnection works fine if I fire up the client when the server is down. The client tries to connects to the server and when I finally fire up the server the connection is estabilished. At some point it may happen that the server decides to disconnect the client, mainly because he logged out invalidating the token and a query on the db tells to do so, or the auth token expired or whatever. IN this circumstance I'd like the restore the server polling by the client because the user may want to login again and he has the rights to connect again to the server. If I refresh the page (client) in the browser it works okay but it's an ugly solution. I think the cause is the "Manager.skipReconnect" property set to true after doing disconnect(), so I'm asking what is the proper way to reinitiate a reconnection polling by the client after the server disconnects a client. Found some answers on stackoverflow about this but all were unsuccessfull, all stuff to be executed in the client: - socket.io.reconnect(); - socket.socket.reconnect(); // ?? - socket = io.connect( 'http://127.0.0.1:3000', ... // reinvoking the connect snippet seems bad idea Could you help me about this matter? Thank you
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: The right way for a client to reconnect after the server does a socket.disconnect( true )
For now, I managed this way and it seems to be stable: Client: [code block]
Trust Score
6 verifications
- 1
For now, I managed this way and it seems to be stable:
For now, I managed this way and it seems to be stable:
Validation
Resolved in socketio/socket.io GitHub issue #2476. Community reactions: 22 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep