Sunday, May 13, 2012

HTML5 Server-sent-Events (using Asp.Net)

       This post may help Asp.Net developers to understand and use Server-sent-Events in their Web Applications. The sample code (provided as download below) demonstrates a simple communication between client(browser) and server, it follows these steps:
  • Client Initiates the process by opening a connection to server.
  • Server pings Client with current Time for every 2second interval for 5 times.
  • After 5 times, Client closes the connection with Server.
       Its useful in transmitting real-time updates as streams of data directly to connected web browsers. Check Server-sent-Events API (events, properties, methods) at MDN site, also check for versions of browsers supporting it. The sample code i provided is just an Asp.Net version of Server-sent-Events in PHP available at MDN.

Above is the screenshot for sample in action (from firefox browser).
   
      You may require to uncomment this line in code:
    //Response.Headers.Add("Content-Type", "text/event-stream\n\n");
    while working against IIS7 and higher versions of web-server.


Note: use other than IE browsers with HTML5 support.

References:
  1.     https://developer.mozilla.org/en/Server-sent_events/Using_server-sent_events
  2.     http://www.w3.org/TR/2011/WD-eventsource-20110208/
Download link:
          Download the code files from here.
   

6 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. wonderful information, I had come to know about your blog from my friend nandu , hyderabad,i have read atleast 7 posts of yours by now, and let me tell you, your website gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts, once again hats off to you! Thanks a ton once again, Regards, Html5 online trainingamong the Html5 in Hyderabad. Classroom Training in Hyderabad India

    ReplyDelete
  3. Pretty interesting post! Thanks it was interesting. into a link

    ReplyDelete
  4. brillant piece of information, I had come to know about your web-page from my friend hardkik, chennai,i have read atleast 9 posts of yours by now, and let me tell you, your webpage gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts, once again hats off to you! Thanx a million once again, Regards, obiee training in hyderabad,informatica training in hyderabad


    ReplyDelete
  5. Thanking now we this blog title and information was really good. I will love that's our selenium online training content.This blog title explains for remove that's the stress and enjoyable working and then understanding the job life.

    ReplyDelete
  6. Hi, We update this blog content is really well.I really easy understand our blog. Very interesting going on this blog.I like this blog concept.SEO Training in Chennai

    ReplyDelete