0
votes

I'm new to SignalR and I am trying to use it to write basically a glorified deli counter take-a-number system. I have it working so the "counter side" people can advance the numbers and it will display on the "customer side" as well as on the other "counter side" computers. However I noticed that if I open a new "counter" page, it doesn't know what numbers the other clients are on now unless someone advances the numbers again before the new page does. If the new window tries to advance the number, it resets everyone to 1 again. Is there a way in SignalR for a new client to see the current state of the other clients, or will I have to persist the data to an external source such as a database or text file? (A database seems overkill for my 3-5 pieces of data.)

I can provide some of my code if necessary, but what I have is working and it's a pretty basic version of a SignalR hub. A lot like the ubiquitous chat tutorials, except that I have 2 client pages, one that is receive only and one that can send as well as receiving.

2

2 Answers

0
votes

You can save the counter state , on your server each client that advances that number will notify the server . and when a new client connectes the server knows that via the OnConnected event , and it can then notify that client on the counter number.

0
votes

You do need some kind of mechanism to store the "state" of your current counter in the server, so that it persists across multiple client sessions. Since you do not have access to the usual .Net Session, you can use HttpRuntime.Cache or the Signal-R client proxy state.

Web Server Cache:

System.Web.HttpRuntime.Cache.Get("Counter")

Client Proxy State:

ChatHubProxy.state.counter= 10;

Hope this helps!