Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket.io - Preventing multiple connections from a client

I just got started in node.js and created a server where browser clients can connect to it.

Problem: When there is an error in the nodejs server and it crashes and restarts, the connected clients will usually reconnect automatically, but I notice that many clients usually make multiple reconnections back to the server!

How can I prevent that from happening, either serverside or clientside?

like image 661
Nyxynyx Avatar asked Apr 23 '26 01:04

Nyxynyx


1 Answers

I suggest implementing it server-side. Apperantly, there is no implementation of it in socket.io (Source Code), so you can use key-value caches like Redis and map every connection in the Redis and check if user is already connected.

like image 171
Mustafa Avatar answered Apr 25 '26 14:04

Mustafa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!