FG
💻 Software📡 Networking

The right way for a client to reconnect after the server does a socket.disconnect( true )

Freshalmost 8 years ago
Mar 14, 20260 views
Confidence Score77%
77%

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

Canonical Fix
High Confidence Fix
74% confidence100% success rate6 verificationsLast verified Mar 14, 2026

Solution: The right way for a client to reconnect after the server does a socket.disconnect( true )

Low Risk

For now, I managed this way and it seems to be stable: Client: [code block]

74

Trust Score

6 verifications

100% success
  1. 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

Worked: 6
Partial: 2
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

socket.iowebsocketrealtime