Context: I'm developing a system similar to Uber's, specifically, the server mediates the flow of data between two types of users (a driver and a client for example), both through their apps by connecting to the server's SignalR hub. Tracking their connection state to the server is mandatory and the process should be as instant as possible.
Their connection state is managed through a HashList<>()
for each type of user (2 Lists). An entry is added to the list whenever a user is connected (OnConnected()
is called), and that entry is removed from the list whenever the user gets disconnected (OnDisconnected()
is called).
These HashLists
are static variables, following the league of this StackOverflow answer.
While debugging locally on my machine, the HashLists gets modified instantly, but when published on a cloud service (in my case: Azure), the lists take time (about 10 ~ 15 seconds) until they are updated. However, acquiring a valid connection with the server just takes about 5 seconds.
Now, I know that connecting to the server can't be instant and it depends on several factors most of them are out of my reach, but detecting disconnections instantly (or as instant as it can get) would solve my problem, what should I do? Is there a different approach I should take?
PS: Detecting disconnections instantly can be done client-side, but this won't help in my case because I need the connected user data in the server.