Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I apply long polling technique in ASP.NET MVC?

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!

like image 201
Selman Genç Avatar asked Dec 19 '13 09:12

Selman Genç


2 Answers

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.

like image 129
SzabV Avatar answered Oct 09 '22 00:10

SzabV


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.

like image 34
Roy Dictus Avatar answered Oct 09 '22 00:10

Roy Dictus