Include to favorites
Log in Logout Register
Start Login Contact Help Photos What's new
Avanced Search
FAQ
RESULTS IN: TEXT IMAGES
 

Hello, Guest
Login  Register
Online: 139 visitors

Blogging (2)
Business (1)
Educational (2)
Gadgets (1)
Games (8)
High Tech News (1)
Internet (1)
PC (2)
PDA (0)
Science (1)
Shopping (6)
Software (1)
Wireless (1)


Browse by date

<< May 2012 >>
MonTueWedThrFriSatSun
123456
78910111213
14151617181920
21222324252627
28293031




Recent searches

Popular searches

Hot this month

Weblogs Archive


GADGETS AND GAMES DIRECTORY :: > Software Register Weblog >  Software Tech Weblogs - WEEKLYBITS.COM GADGETS AND GAMES DIRECTORY
Yahoo User Interface Blog
generated by http://wordpress.org/?v=3.0.4  en Blogger
SEND A FRIEND
Suscribing to  please login first
User: Login

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications.
News and Articles about Designing and Developing with Yahoo! Libraries.Visit Yahoo! User Interface Blog
Address URLhttp://www.yuiblog.com/blog    Registered: 26-Apr-2008
Ads:

Send to email
Visit In the YUI 3 Gallery: Server-Sent Events In the YUI 3 Gallery: Server-Sent Events in DevelopmentYUI 3 Gallery
By Nicholas C. Zakas
el 29-Nov-2010

Push notifications on the web are increasing in popularity, as evidenced by the excitement over Web Sockets, and with good reason. The web is moving towards more accurate and up-to-date information as audiences turn to the Internet for real-time updates of stocks, news, sports, and more. While Web Sockets represents a giant leap forward in the realm of push notifications, there is a lesser-known spec that can be considered a small jump forward: Server-Sent Events.

Server-Sent Events (SSE) are also targeted at making push notifications easier by building on top of the techniques that developers are already using. As opposed to Web Sockets, SSE uses regular HTTP to communicate with the server and allows you to decide whether to use HTTP streaming, long polling, or even regular polling to retrieve new data (though this isn’t recommended).

At the heart of SSE is the EventSource object. The YUI 3 Gallery EventSource module creates a cross-browser implementation of EventSource, bringing support for Server-Sent Events to all browsers that support the XMLHttpRequest, including Internet Explorer 6, while falling back to the native implementation in browsers that have it (currently Safari 5, Chrome 7, and Opera 10.7).

The EventSource interprets a response as an event stream (signified by a content type of “text/event-stream”) and fires appropriate events. There are three predefined events:

  • open – fires when the connection with the server has been established.
  • message – fires when a new message is received from the server. The event.data property contains the new data.
  • error – fires when an error occurs in processing the event stream. Once this event fires, no further events will be processed and the server connection is permanently closed.

The event stream itself is plain text data made up of the keyword “data:” followed by some data on a single line. If you wish to have multiple lines, you must include more rows with “data:” prefixes. A empty line is considered the boundary between events. Here’s a simple example:

data: hello

data: hello
data: world

Two message events are fired with this event stream. The first has event.data set to “hello” while the second has event.data set to “hello\nworld” (note the new line).

Here’s an example of creating a new EventSource instance:

YUI({
    gallery: 'gallery-2010.11.17-21-32'
}).use('gallery-eventsource', function(Y) {

    var src = new Y.EventSource("stream.php");

    src.on("open", function(event){
        console.log("Connection opened!");
    });

    src.on("message", function(event){
        console.log("Data received: " + event.data);
    });

    src.on("error", function(event){
        console.log("Error!");
    });

});

The constructor accepts a single argument, which is the URL of the event stream. The interesting and useful part of EventSource is that it will automatically reconnect to the server if the connection is lost for any reason. Doing so frees developers from needing to worry about disconnecting and reconnecting, a frequent complaint when using XMLHttpRequest for push notifications.

Even though the YUI 3 Gallery EventSource module matches the specification with support for HTTP streaming, long polling, and regular polling, not all browsers support all three. Internet Explorer (up to and including version 9) does not support HTTP streaming, while it can easily handle long or regular polling. The recommended usage of this module is to build your experience with a long polling implementation for best performance and compatibility.

If you’d like to optimize for browsers that support HTTP streaming, the module sets a special X-YUIEventSource-PollOnly header when it detects a browser that can’t use HTTP streaming. You can check for this header on the server to determine the correct way to serve data. Here’s an example implementation using JSP:

<%@page contentType="text/event-stream" buffer="none"%>
<%

    //check for poll-only header
    String header = request.getHeader("X-YUIEventSource-PollOnly");

    //check every so often to see if there's new data
    while(true) {        

        //sleep for a second - simulate waiting for data
        Thread.sleep(1000);        

        //output the current time, ensure there are two trailing newlines
        out.print("data: " + (new java.util.Date()).toString() + "x\n\n");
        out.flush();

        //if it's a poll-only request, break the loop,
        //which ends the request - the client will reconnect
        if (header != null){
            break;
        }
    }
%>

It’s fairly easy to migrate existing long polling solutions to use SSE, provided the data format is simple. Since the format of event streams is line-based, that could mean reformatting some data to sit on a single line instead of multiple lines.

While SSE will never have the same performance characteristics as Web Sockets due to using HTTP, it does represent a logical evolution of push notifications in browsers. SSE can replace older XMLHttpRequest-based solutions with less code and better error handling, all while keeping the same authentication paradigm.

The YUI 3 Gallery EventSource module implements almost all of the SSE spec (you can see in the source code which parts are not yet implemented by searching for “TODO” comments). This is because some of the features are vaguely described. The module supports the following features:

  • Simple events (fire message event).
  • Custom events (fire an event matching the name specified in “event:”)
  • Event IDs (captured in event.lastEventId and sent to the server)

The parts that have yet to be implemented are support for reconnection times and the event.origin property. Otherwise, everything else should behave the same as the native implementation.

Further Reading

  • Introduction to Server-Sent Events
  • The Long Journey of Server-Sent Events


Read 17 times

Suscribing to  please login first
In the YUI 3 Gallery: Server-Sent Events -  Tech Weblogs - WEEKLYBITS.COM  Blogger Is a collection of i

Photologs

Yahoo User Interface Blog Blogger

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries.

In the YUI 3 Gallery: Server-Sent Events
Push notifications on the web are increasing in popularity, as evidenced by the excitement over Web Sockets, and with good reason. The web is moving towards more accurate and up-to-date information as audiences turn to the Internet for real-time updates of stocks, news, sports, and more. While Web Sockets represents a giant leap forward in [...] [..] Read complete article
Subscribe to In the YUI 3 Gallery: Server-Sent Events
Published 29-Nov-2010 by Nicholas C. Zakas in DevelopmentYUI 3 Gallery
Read 17 times. More hits in More articles In the YUI 3 Gallery: Server-Sent Events Images about In the YUI 3 Gallery: Server-Sent Events
Kotaku`s The Gamers Guide Blogger

XBOX 360 Gamers Weblog Gossip, news and leaks for obsessive gamers Kotaku As if you don't waste enough of your time in a gamer's haze, here's Kotaku: a gamer's guide that goes beyond the press release. Gossip, cheats, criticism, design, nostalgia, pred

Events [Note]
To: Ash From: Crecente Re: Electric Toothbrushes Are Great Man, gaming travel starts earlier and earlier each year. We've already been to Vegas for CES and now I'll be taking a trip to Microsoft's X10 in San Fran next week and later in the month Totilo will be heading out to DICE in Vegas. And of course March is the Game Developers Conference. This is going to be another incr [..] Read complete article
Subscribe to In the YUI 3 Gallery: Server-Sent Events
Published 02-Feb-2010 by Brian Crecente in Noteday note
Read 13 times. More hits in More articles Events [Note] Images about Events [Note]
Kotaku`s The Gamers Guide Blogger

XBOX 360 Gamers Weblog Gossip, news and leaks for obsessive gamers Kotaku As if you don't waste enough of your time in a gamer's haze, here's Kotaku: a gamer's guide that goes beyond the press release. Gossip, cheats, criticism, design, nostalgia, pred

Why We Don't Do Review Events [Note]
To: Ash More » [..] Read complete article
Subscribe to In the YUI 3 Gallery: Server-Sent Events
Published 10-Nov-2010 by Brian Crecente in Noteday note
Read 0 times. More hits in More articles Why We Don Images about Why We Don
Kotaku`s The Gamers Guide Blogger

XBOX 360 Gamers Weblog Gossip, news and leaks for obsessive gamers Kotaku As if you don't waste enough of your time in a gamer's haze, here's Kotaku: a gamer's guide that goes beyond the press release. Gossip, cheats, criticism, design, nostalgia, pred

The Day's Events [Night Note]
To: Crecente From: Luke Re: Paternity Serious paternity time? I imagine there's no other kind. You know, when you don't have kids, it gets really hard to write these things. I mean, today, I woke up, played some Rock Band, wrote about video games, played some Fable II, wrote about video games, ate a great meat [..] Read complete article
Subscribe to In the YUI 3 Gallery: Server-Sent Events
Published 20-Nov-2008 by Luke Plunkett in night note Note
Read 0 times. More hits in More articles  The Day Images about  The Day
Thoughts From Kansas Blogger

Weblog of a University of Kansas ecology and evolutionary biology student, fighting for progressive politics, evolution, and endangered species.
Thoughts from Kansas You will notice that it lacks definiteness; that it lacks purpose; that it lacks coherence; that it lacks a subject to talk about; that it is loose and wabbly; that it wanders around; that

Skeptical Bay Area events
Tomorrow (Wednesday), Bay Area Skeptics will be hosting the excellent Rebecca Watson for a Skeptics in the Pub Quiz. Watson is a founder of Skepchick, a host of the Skeptics Guide to the Universe, and a force for skepticism and sensibility in a world that is too frequently senseless. As a member of the Bay Area Skeptics board, I'm pretty jazzed about this event. You can play [..] Read complete article
Subscribe to In the YUI 3 Gallery: Server-Sent Events
Published 18-May-2011 by Thoughts in Culture Wars
Read 11 times. More hits in More articles Skeptical Bay Area events Images about Skeptical Bay Area events
Joystiq Blogger

Covers video game news from an independent, unbiased perspective
Joystiq Joystiq

ESA holding charity events during E3
Click here to read Is There A Future In Bendable Gaming? - Is There A Future In Bendable Gaming? [Innovation] Did you know that by attending this year's E3, you won't just be filling your pants with game-based thermoses and probably catching swine flu? No, this year you'll be helping to give back with charity events the ESA has set up durin [..] Read complete article
Subscribe to In the YUI 3 Gallery: Server-Sent Events
Published 06-May-2009 by Justin McElroy in charitye3e3-2009esa
Read 20 times. More hits in More articles ESA holding charity events during E3 Images about ESA holding charity events during E3
Nerdblog Blogger

Provides news about hardware, software, notebooks, laptops, PCs, Mac, PDAs
Nerdblog.Net

How to Set Up a Home Server
If you’re curious about running your own website, broadcasting your tunes to your friends or create your own file-storage system, you’re going to need some hardware first. This guide from Webmonkey will help you build a machine you can use to become the master of your own digital domain. [...] [..] Read complete article
Subscribe to In the YUI 3 Gallery: Server-Sent Events
Published 15-Aug-2008 by Nerdblog in General
Read 19 times. More hits in More articles How to Set Up a Home Server Images about How to Set Up a Home Server
Nerdblog Blogger

Provides news about hardware, software, notebooks, laptops, PCs, Mac, PDAs
Nerdblog.Net

How to Backup a Web Server
Your hard drive is backed up, your documents, family pictures, even your car keys. Now why isn’t your web server? Web servers aren’t infallible and you can lose your hard work in seconds. Have we struck the fear of apocalypse in you yet? We have a solution. We’ll help roll your HTML and CSS up [...] [..] Read complete article
Subscribe to In the YUI 3 Gallery: Server-Sent Events
Published 01-Aug-2008 by Nerdblog in General
Read 30 times. More hits in More articles How to Backup a Web Server Images about How to Backup a Web Server
Yahoo User Interface Blog Blogger

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries.

Using Your App?s YUI Components on the Server
For my first sprint of 3.6.0 development I’m writing up (and showing by example) how to develop an app using YUI on the client and server, which works on both the desktop and mobile devices. Code sharing and reuse FTW! To start this process, I wanted to first build something using the development approaches that [...] [..] Read complete article
Subscribe to In the YUI 3 Gallery: Server-Sent Events
Published 23-Apr-2012 by Eric Ferraiuolo in DevelopmentYUI Implementations
Read 2 times. More hits in More articles Using Your App?s YUI Components on the Server Images about Using Your App?s YUI Components on the Server
Nerdblog Blogger

Provides news about hardware, software, notebooks, laptops, PCs, Mac, PDAs
Nerdblog.Net

VMware Server 2.0 i RC1
Gratisversjonen av VMwares virtualiseringsmotor, tidligere kjent som GSX Server, er snart klar i versjon 2.0. Hardware.no [..] Read complete article
Subscribe to In the YUI 3 Gallery: Server-Sent Events
Published 06-Jul-2008 by Nerdblog in General
Read 35 times. More hits in More articles VMware Server 2.0 i RC1 Images about VMware Server 2.0 i RC1

Warning We are not responsible of information posted from external feeds. Use this website at your own risk. Notice: We will not be liable for any direct or indirect loss or damage arising under this disclaimer or in connection with our website, whether arising in tort, contract, or otherwise.


Your Site here Your Site here Your site here Your site here Your site here