Simple scenario:
- Client connects to server with socket.io (
socket = io.connect(...)
) - Server crashes
- Client tries to reconnect
- User tells client to disconnect (
socket.disconnect()
) - Server starts
- Client reconnects
It seems that once socket.io starts attempting to reconnect, it cannot be stopped anymore. I want step 4 to prevent step 6 from happening, but it doesn't. What do I have to call instead?
In a new socket.io 1.1.x you can do the following:
Here is blog link.
You might want to handle the reconnection yourself.
Note: old versions used
reconnect
instead ofreconnection
.I think what you need is to configure
socket.io
client
to notreconnect
is set propertyreconnect
tofalse
I created a little server(
server.js
) to test this:Then I created this
test.js
to test that it does not reconnectFor
test.js
to work you will need to installsocket.io-client
fromnpm
issuingnpm install socket.io-client
or by addingsocket.io-client
(dev-)dependency
to yourpackage.json
.When I stop
server.js
whiletest.js
is runningtest.js
will return immediately which I believe is your desired result. When I setreconnect
totrue
the client will try to reconnect to server which is not the desired behaviourTry the following code: