3jay1
3jay1

Reputation: 107

Reconnect a WS instance that fails to connect in a given amount of time

I have a program that uses ws in node to create ~3000 websocket instances and connect them to a server.

When a ws instance fails to connect within a certain amount of time (lets say 3 seconds for example) I would like to attempt to reconnect the websocket.

I have tried several methods to accomplish this but they all involve iterating over all of the websocket instances, looking for specific conditions and then either re-calling my connect function or destroying the instance and creating a new one.

It seems like it is a cumbersome way of doing this especially when I try and speed up the process. Is there a less costly way of doing this?

Edit: I have also tried setting a timeout when the instance is created that after 3 seconds checks to see if readyState is still 0 and if it is it reconnects but this also seems to slow down my program.

Upvotes: 1

Views: 26

Answers (0)

Related Questions