Question

I search a lot about polling technique but i can't find anything about how to apply this technique in asp.net mvc. There are so many articles and documentation but most of them about php and ajax.

I want to use this technique with my project in two places,one is the tweet system like twitter and other is chat system. I'm curious what is the best way to apply this technique in MVC ? Do I have to use SignalR ? Is this the best option?

If you can give me some sample or documentation it would be great, thanks!

Was it helpful?

Solution

SignalR is definitely the way to go if you want to push data from the server to the client. I tried to do this once using a less well supported and developed library and I got it to work but from what I've seen of the SignalR examples it's way easier than what I did. Start reading the docs and example code on asp.net it's relatively straight forward.

Here is an article on Code Project that shows you how little code you need to achieve a server to client push.

http://www.codeproject.com/Articles/524066/SignalR-Simple-Chat-Application-in-Csharp

This is because all the heavy lifting for communication establishment is done by SignalR's API on the server in .Net and on the client in JavaScript.

OTHER TIPS

What the "best" solution is, is up for debate, and this forum is not about that.

If what you want to do is real peer-to-peer communication, SignalR doesn't do that -- it is designed to push data from a server to a client and to do remote procedure calls (RPCs) from the server to the client.

If what you want is n-way communication via a server as a central hub, then SignalR is certainly the way to go. It is proven technology and has Microsoft's full support behind it.

Microsoft has published a tutorial about working with SignalR 2.0 (http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-getting-started-with-signalr-20) that implements a chat application.

If you want a simple way of using SignalR for event based communication you can have a look at my Library thats built on top of SignalR.

You can see here how to set it up

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

You can also download the Demo to test it and learn that way

https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy/tree/master/SignalR.EventAggregatorProxy.Demo.MVC4

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top