Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11571

Socket.io How to properly handle client reconnection on a server side

$
0
0

I have a mobile app which may loose a connection with a server, for instance a network switched from 4g to wifi.In this case it tries 3 times to reconnect with a server. And it usually succeeds.But right now my server always fires the event disconnect and deletes user even if he reconnected.

Right my server side code looks like this:

socket.on('disconnect', function() {    deleteUser();});

What I want is if user successfully reconnected, do not delete it.In other words:

socket.on('disconnect', function() {    if (user reconnected after n reconnection tries) return; // do not delete     deleteUser(); // user didn't reconnect after n tries, delete him.});

But I don't know how to implement this logic on a server.Any advice?


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>