Fahad Abid Janjua
Fahad Abid Janjua

Reputation: 1024

Consistently Push Data From Server to Client Using SignalR

I am working on a web application where i have some charts and i want to consistently get data from the database for the charts so that the user will always have the latest picture of the data. I used signalR and on the page load of Report page i am calling a server method in hub's class which is getting chart data from database and passing it onto the client and in turn a handler at client processes the data and draws the chart. What i want is to keep getting the data consistently. What are my options for it?

What is the best way to keep calling hub's method after a fix interval of say one minute?

Upvotes: 1

Views: 3661

Answers (2)

Anders
Anders

Reputation: 17554

I would not poll on client or server. Instead use a service bus and publish your changes on that bus when they occur.

You can then forward these events to the client using SignalR. I have made a library for just that called SignalR.EventAggregatorProxy

https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy/wiki

I wrote a blog post about it here http://andersmalmgren.com/2014/05/27/client-server-event-aggregation-with-signalr/

You can also look at the demo https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy/tree/master/SignalR.EventAggregatorProxy.Demo.MVC4

Or look at the live demo here http://malmgrens.org/signalr/

Upvotes: 5

Schadensbegrenzer
Schadensbegrenzer

Reputation: 950

SignalR makes polling the server obsolete. What you want to do is to schedule your database access. If you want to update your charts every minute, create a timer job in the server app where you collect data from database which has been added within the last minute. Then send this data to your clients. On this way your connected clients are always up to date without polling the server.

Upvotes: 4

Related Questions