How to add in comet implementation in a ASP.Net MVC3 website? [closed]
I'm trying to have my website have a similar functionality to this one:
[removed]
Basically the counters go down, and every time someone bids on that item, the counter is reset to 15 seconds.
I suspect I need to use a comet like implementation, no? Am I correct in this assesment?
I don't think every auction on that page is constantly pinging the server for updates, rather the server is fowarding the message "Hey, someone bid here!" to the website.
Here's the thing, I've never done comet like behavior on a website, and according to this question (which is very dated), it's very difficult to do in ASP.Net.
Do I need comet here or are there better alternatives?
It doesn't use comet at all. As you can see in firebug it keeps doing ajax requests and receiving JSON to update the data.
I did some recent testing & research with comet ( I need it in an upcoming project), and I found out that Websync from Frozenmountain and PokeIn are the best options so far. It's just 2 difficult and 2 much time consuming to write your own implementation. You can have an up and running great one for just a small price.
Edit 19/02/2012
There is a new alternative.
SignalR
What I have done in the past was to get the same result using Async Actions in MVC.
Basically what you need is an async MVC controller that holds the request until something has changed in the server.
Your client will send an ajax request to the server, the request will wait in the async action until something has changed in the server and then returned to the client, the client process the request, and sends another request to the server waiting for more changes. This will give you the instant feedback you are looking for,
I've implemented something similar but without using an Asycn controller (since this app won't have many concurent users.) But the idea is the same, you just have to convert it to Async if you need it to scale for many users.
[HttpGet]
public JsonResult Comet(string message)
{
MiniProfiler.Stop(true);
var currentMessage = GetCurrentMessage();
while (message == currentMessage)
{
Thread.Sleep(250);
currentMessage = GetCurrentMessage();
}
return Json(currentMessage, JsonRequestBehavior.AllowGet);
}
MVC Controller
https://github.com/kayone/NzbDrone/blob/master/NzbDrone.Web/Controllers/NotificationController.cs
Client Side
https://github.com/kayone/NzbDrone/blob/master/NzbDrone.Web/Scripts/Notification.js
This blog post shows how to add a realtime stock counter to an ASP.NET MVC 3 application. This sounds really similar to the functionality that you are looking for so may well be useful.
The solution/blog post uses Pusher, a hosted service who I work for, so you don't need to worry about the realtime infrastructure at all. It also uses WebSockets which will ultimately supersede polling or any other type of realtime mechanism such as http long-polling or http streaming.
精彩评论