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

3

8

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!

Coelho answered 19/12, 2013 at 9:40 Comment(2)
SignalR documentation.Appalling
There's a similar question here but while neither of the current answers provide the code you are after they do explain how tricky long polling is to get right (e.g. this answer discusses IIS settings issues and load balancing concerns, while this answer notes how long polling can degenerate into short polling or even into a self-imposed denial of service attack!)Letaletch
S
9

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.

Showers answered 19/12, 2013 at 9:46 Comment(1)
You could improve your answer by adding the links. Perhaps you could also give some info about why it is the way to go.Anurous
C
5

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.

Colbycolbye answered 19/12, 2013 at 9:53 Comment(0)
O
2

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

Ornamental answered 19/12, 2013 at 14:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.