3

I'm trying to use SignalR version 1.2.1 with Mono 2.10 (in my existing project). Basically it works great. But when coming to Connection and Disconnection, the count is never matching. I'm trying to keep track of the clients connected and update the clients accordingly. Here is my use case,

I'm having three frames loaded with three different pages. Top (used for real-time updates), Left tree(for page navigation) and right page (actual content page). The top page will remain forever and which will be constantly updating the real time values (i require to connect to the hub here). Similarly in one of the content page (say page A), i need to connect to SignalR and SignalR should constantly update some real-time information, until I'm connected in this page A. I'm thinking of starting a timer in the hub when the user navigates to this page and keep on pushing the data to the connected clients. Once the user navigates out of page A (or closes the browser), i should stop the timer. There are also chances like multiple users connected at page A, hence i should make sure that there are no clients currently in page A before stopping the timer.

To test this I'm just having a static variable to increment and decrement the counter as and when user is connected/disconnected from page A. I'm doing this in OnConnected and Ondisconnected events of the hub. The problem is, I'm always getting OnConnected event. But I'm not getting OnDisconnected event all the time. I have tried various scenarios like navigating to other page within my website, reloading same Page A again, closing the tab/window etc., But I'm facing problem most of the time in page navigation. It is not calling disconnect always and my counter never comes down to zero again. I tried setting the timeouts but that also doesnt seem to call disconnect.

Can anyone help me on this? How to detect the clients disconnection and stop the timer? Thanks in advance.

PS: I have to stick to Signal 1.2.1 due to the .NET framework 4.0 requirement. i.e., i cannot update to 4.5.

Reuben
  • 268
  • 3
  • 15

1 Answers1

1

I think you should add a persistent data storage on the server and let the server manage the client the time out for client which are OnDisconnected event is not fired for.

try the following sample :

https://github.com/DamianEdwards/NDCLondon2013/tree/master/UserPresence

and look at this thread SignalR OnDisconnected - a reliable way to handle "User is Online" for chatroom?

Community
  • 1
  • 1
Shachaf.Gortler
  • 5,655
  • 14
  • 43
  • 71
  • Hi, Thanks for the answer. I did take a look on the UserPresence project and tried that. It works great in IIS. But when it comes to Mono, it seems that the heartbeat is not working properly. I'm always getting ItrackingConnection.IsAlive property as true even for the connection which is not currently active. I dont find any good documentation on this hearbeat tracking. Can you please help me on that? or is there any other mechanism to implement this heartbeat. Please suggest. I'll post the code if required. – Reuben Jun 18 '14 at 10:34
  • I'm not familiar with mono .I suggest your write a new question , and tag it as mono – Shachaf.Gortler Jun 18 '14 at 13:12