ASP.NET - problem with heavy connection with AJAX / JQUERY

I wrote an update file that updates several divs every second using serveride information. Now the problem is that it seems very difficult, in google chrome my manipulation even continues to load.

Hope someone can tell me how best to do this script or maybe get a different solution.

Here is my aspx page:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns='http://www.w3.org/1999/xhtml' > <head id="Head1" runat='server'> <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script src="Scripts/jquery.countdown.js" type="text/javascript"></script> <title>Page</title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <script type="text/javascript"> $(function hello() { // function that does something exciting? var liftOff = function () { // .... }; // Get a date that is some (short) time in the future var getDeadline = function () { var shortly = new Date(); shortly.setSeconds(shortly.getSeconds() + 5.5); return shortly; }; // Attach click handler to all our buttons $("button.resetButton").click(function (event) { $.ajax({ type: "POST", url: "WebService.asmx/HelloWorld2", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) {}, failure: function () { alert("Uh oh"); } }); }); function highlightLast5() { $.ajax({ type: "POST", url: "WebService.asmx/HelloWorld", data: "{'number':'0'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { $("div.shortly").countdown('change', { until: msg.d }); }, failure: function () { alert("Uh oh"); } }); } // Start all countdowns going on page load $('div.shortly').countdown({ until: getDeadline(), onTick: highlightLast5, onExpiry: liftOff, layout: '{sn}' }); }); </script> <div class="mainpanel"> <div> test </div> <div class="shortly" > </div> <button id="button" type="button" class="resetButton"> Reset </button> </div> </form> </body> </html> 

And a web service that returns information:

 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; /// <summary> /// Summary description for WebService /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class WebService : System.Web.Services.WebService { List<Auction> auctions; public WebService () { //Uncomment the following line if using designed components //InitializeComponent(); auctions = (List<Auction>)Application["Auction"]; } [WebMethod] public string HelloWorld(int number) { return auctions[0].seconds.ToString(); } [WebMethod] public void HelloWorld2() { auctions[0].seconds = 30; } } 

Now that you can see that the jquery script receives data every second, this is necessary because it is for a live auction. If I use this script on a real server, since I tried to get the server to crash for about 2 minutes due to heavy use, this, unfortunately, has only one open client. Therefore, whenever clients use a script, I get a real problem.

+4
source share
2 answers

Since you want to live streaming, you can try Comet using, say, WebSync . You could compress much more productivity, and it would be more scalable.

+3
source

On the technique of comets.

Here is a similar question with an answer. Pushing messages for clients from a server application?

The comet does not call the server every second, but simply opens a connection, which remains open on the server side when the server has something to play its replay and close the connection, etc.

http://en.wikipedia.org/wiki/Comet_(programming) )

http://www.frozenmountain.com/websync/

http://www.aaronlerch.com/blog/2007/07/08/creating-comet-applications-with-aspnet/

+3
source

All Articles