Reputation: 2034
I have socket.io running with Express. When I CTRL-C on the Terminal to stop the server running, the browser continues to report the following:
I found various similar questions, none of which have helped me resolve my question.
Could anyone show me how to tell socket.io to cancel reconnection attempts when the server stops running.
Many thanks in advance
Upvotes: 1
Views: 3030
Reputation: 239
My solution.
let socket = io.connect(null, {port:5000, rememberTransport: false});
Upvotes: 1
Reputation: 2034
I've found a solution.
I still wonder why some events in socket.io just don't seem to get fired but perhaps that's another question. The code that helped me resolve my question is:
var socket = io.connect('http://localhost:3000', {'reconnection': false});
Thank you for your contributions
Upvotes: 3
Reputation: 2672
The short answer:
Stop pressing CTRL-C
, kidding.
The long answer:
There are a couple of things you could do:
1) You could change the reconnection options on the client, perhaps set reconnection
to false. But maybe this is not desirable for the real world, so instead you could do:
2) Disconnect the client socket from the server right before the server exits. The exit strategy for this will depend on what server you use.
3) If options one and two are not viable, then there isn't much you could do since you are shutting down the server and leaving your client hanging — stuck in time thinking that the server will someday return. Not that it cares, though. You're console is the one with the big mouth...
I hope that helps!
Upvotes: 1