Is Comet easier in ASP.NET with Asynchronous Pages?

血红的双手。 提交于 2019-12-12 11:06:58

问题


I don't mean to ask, is Comet easier in ASPNET than in Jetty? I mean, is Comet easier inn either ASPNET or Jetty, as compared to other alternatives? I think the asynch capabilities of ASP.NET and Jetty specifically make Comet more scalable when implemented on those platforms and I'd like to confirm that.

ASPNET introduced "Asynchronous pages" back in 2005. The idea was to apply the familiar .NET asynch model to ASP.NET page processing.

public partial class AsyncPage : System.Web.UI.Page
{
    private WebRequest _request;

    void Page_Load (object sender, EventArgs e)
    {
        AddOnPreRenderCompleteAsync (
            new BeginEventHandler(BeginAsyncOperation),
            new EndEventHandler (EndAsyncOperation)
        );
    }

    IAsyncResult BeginAsyncOperation (object sender, EventArgs e, 
        AsyncCallback cb, object state)
    {
        _request = WebRequest.Create("http://msdn.microsoft.com");
        return _request.BeginGetResponse (cb, state);
    }
    void EndAsyncOperation (IAsyncResult ar)
    {
        string text;
        using (WebResponse response = _request.EndGetResponse(ar))
        {
            using (StreamReader reader = 
                new StreamReader(response.GetResponseStream()))
            {
                text = reader.ReadToEnd();
            }
        }

        Regex regex = new Regex ("href\\s*=\\s*\"([^\"]*)\"", 
            RegexOptions.IgnoreCase);
        MatchCollection matches = regex.Matches(text);

        StringBuilder builder = new StringBuilder(1024);
        foreach (Match match in matches)
        {
            builder.Append (match.Groups[1]);
            builder.Append("<br/>");
        }

        Output.Text = builder.ToString ();
    }
}

Q1: Doesn't this make ASP.NET scale much better for Comet-style applications? Has anyone used this and tested it?

I think that other server-side frameworks also have something similar. If I'm not mistaken Jetty has something like this, to enable better scale in Comet scenarios.

Q2: Can anyone shed light on that?


回答1:


The asynchronous processing in .NET does indeed provide a basis for building comet applications. Specifically, it's the IHttpAsyncHandler that can be used as a foundation.

That said, without a third-party library, implementing Comet from scratch is... difficult. There's a .NET implementation of Comet for IIS called WebSync that would compare against Jetty.



来源:https://stackoverflow.com/questions/1756576/is-comet-easier-in-asp-net-with-asynchronous-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!