user2190690
user2190690

Reputation: 2034

how to stop socket.io client reconnection attempts

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:

Console output after server is interrupted

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

Answers (3)

Jhanvi Patel
Jhanvi Patel

Reputation: 239

My solution.

let socket = io.connect(null, {port:5000, rememberTransport: false});

Upvotes: 1

user2190690
user2190690

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

m-a-r-c-e-l-i-n-o
m-a-r-c-e-l-i-n-o

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

Related Questions