Click here to Skip to main content
15,886,578 members
Articles / Web Development / HTML

Using IHttpAsyncHandler and XMLHttpRequest to “push” messages to the client

Rate me:
Please Sign up or sign in to vote.
4.75/5 (14 votes)
30 Sep 2009CPL4 min read 84.3K   2K   61  
How you can let a web browser be a "listener" for chat messages pushed from a web server.
//
// This code is released under Common Public License Version 1.0 (CPL)
// Full license text is available at http://www.opensource.org/licenses/cpl1.0.php
//
// Author  : Karel Boek
// Date    : Sept 29, 2009
// Contact : karel.boek@raskenlund.com
//

using System;
using System.Web.UI.WebControls;

namespace SandBox.CometSample
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            if (IsPostBack)
                return;

            ltlSessionId.Text = Session.SessionID;
            
            foreach (var sessionId in Global.Sessions)
                if (sessionId == Session.SessionID)
                    ddlSessions.Items.Add(new ListItem("Myself", sessionId));
                else
                    ddlSessions.Items.Add(new ListItem(sessionId, sessionId));
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Public License Version 1.0 (CPL)


Written By
Software Developer Raskenlund
Norway Norway
Professional System Architect and Developer

Comments and Discussions