Forum Controls
Spotlight Features

The Rich Engineering Heritage Behind Dependency Injection

Andrew McVeigh takes us on a tour of the rich heritage behind dependency injection, what it represents, and tells us why its here to stay.

NetBeans 6: Matisse Updates

NetBeans 6 delivers great updates to the Matisse GUI builder. Spend a few minutes with Roman Strobl and get an expert briefing on what's new and what has changed.

Introduction to Groovy Part 3

In this, the third and final installation of Andres' Introduction to Groovy series, you learn about how Groovy handles variable numbers of arguments, named parameters, currying, and more about Groovy operators. Including, some new operators.

Easier Custom Components with Swing Fuse

Swing Fuse (actually just Fuse), is a framework designed to make it easier to create your own custom desktop components. In this article, Daniel Spiewak shows you how to get started and provides sample source code you can download.

Benchmark Analysis: Guice vs Spring

Willam Louth shows how he uses JXInsight Probes to investigate probable performance issues with code bases that he is not familiar with. He also highlights possible pitfalls in creating a benchmark, as well as in the analysis of results.
Replies: 21 - Pages: 2   [ 1 2 | Next ]
Threads: [ Previous | Next ]
  Click to reply to this thread Reply

Server-sent events: the web upside down

URL: Jose M. Arranz

At 9:53 AM on Dec 28, 2007, Jose María Arranz Santamaría wrote:

In the web development space everybody knows how a browser generated event can be dispatched by the server: a simple click on a link requests a new page or sends an AJAX request to the server; these are client-sent events. These days we can hear a "new" concept: "server-sent events" related to Comet.

But what are server-sent events?

The Wikipedia gives you a clue :

Called server-sent events, it attempts to avoid the disadvantages of other Comet transports, while making Comet applications much more straight-forward to implement, both on the server side, and in the browser-side JavaScript. The server-sent event portions of the HTML 5 specification stipulate both a new HTML element, event-source, and a new data format, called the DOM event stream. JavaScript can be used to attach callback functions to multiple types of events.

In this case The Wikipedia is not the best place to learn, the Web Hypertext Application Technology Working Group (WHATWG) shows this better:

This section describes a mechanism for allowing servers to dispatch DOM events into documents that expect it. The “event-source” element (HTMLEventSourceElement) provides a simple interface to this mechanism.

In a few words, server-sent events are “events” sent to the client using a permanent HTTP connection with a content type “application/x-dom-event-stream”. Server “events” are simple text like these:


Event: server-time
data: [time on the server]

Event: the-answer
data: 42


This will send two events to the browser, and it's possible to catch them as DOM events. The following JavaScript example listens for the "server-time" event, and alerts the content.


document.getElementsByTagName("event-source")[0]
.addEventListener("server-time", eventHandler, false);

function eventHandler(event)
{
// Alert time sent by the server
alert(event.data);
}


In this example, taken from Arve Bersvendsen’s blog a member of the Opera crew, the event type is user defined (standard events could be supported).

May be you know that since 2005, the Web Hypertext Application Technology Working Group (WHATWG) is working to include this approach as part of the HTML 5 specification. May be you know Opera 9 is the first browser supporting this new technique. And finally may be you know this "new" technique is ignored by any other browser... two reasons:


  1. HTML 5 is a draft

  2. Microsoft Internet Explorer has largely ignored the W3C DOM Events standards (neither IE 7). Any plans to support the old (year 2000) W3C DOM Events Level 2 specification?



May be you say "Bad news, this technology is amazing to build web applications with server-push a.k.a Comet requisites".

Don’t worry, server-sent events is a kind of Comet, you can ever use server generated JavaScript to execute client code using Comet techniques. Of course this is similar but is not the same.

Can we use server-sent events now?

Yes!

ItsNat , a new open source AJAX based Java web application framework, provides a server-sent event technique using W3C standards. ItsNat sever-sent events implementation is not of course standard but it falls near the proposed standard (in fact ItsNat version is more advanced).

ItsNat simulates a Universal W3C Java Browser at the server, the server mimics the behavior of a web browser, containing a W3C DOM Level 2 node tree and receiving W3C DOM Events fired by the browser using AJAX requests.

With this foundation is not difficult to create in the server a Java W3C DOM event (for instance a mouse “click” event) and dispatch to a server based W3C DOM element as target. ItsNat automatically sent this event to the browser using Comet techniques, converted to a native event and dispatched to the client symmetric target element. If the target DOM element in the server is listening this type of event (a listener was registered in the server), the client forwards again the event to the server.

With this technique we can simulate user actions from the server, opening a new world of uses:

* Server based functional web testing with no external tools

Using the real browser and the power of Java. Server based functional web testing has the following advantage: as the test code is in the server, can test whether the business data is correct (data was created, updated and removed correctly). With ItsNat the view can be tested checking the server DOM tree too.

* AJAX Bookmarking

A permalink system may be defined to save concrete states of the AJAX web application. When the AJAX application is loaded using a permalink the server can simulate the necessary user actions to drive the application to the desired application state on load time.

* Add yours…

ItsNat goes further introducing an alternative "server-sent events" technique: W3C DOM events fired by the server dispatched directly to the server W3C DOM without browser interaction, following the W3C DOM Events standard including “capturing” and “bubbling” phases. In this case no browser is used, no network latencies, synchronous execution (this avoid the typical waits when testing an asynchronous AJAX application using the browser mode).

On testing both modes are complementary (source code is basically the same), if the "no browser" test fails of course the "browser based" test would fail.

The “no browser” mode is valid to make AJAX applications “searchable” by Google/search engines, because the initial state is built in the server with no browser interaction (no JavaScript is used).

Follow this link to see server-sent events in action.

What do you think about these server-sent events techniques?

What kind of applications can be beneficed by server-sent events or server-push (Comet) in general?

What problems do you find when testing or bookmarking an AJAX application?

How do you achieve your AJAX application is Google (Yahoo etc) searchable?
1 . At 5:37 AM on Dec 31, 2007, Roger Voss wrote:
  Click to reply to this thread Reply

Re: Server-sent events: the web upside down

There's a legend about the Gordian Knot. Great thinkers from all around came to try and figure out how to undo the Gordian Knot - but all failed. And then one day Alexander the Great came to take on the challenge of the Gordian Knot. He took one look, drew his sword, and cleaved the knot in two. Problem solved.


Today so-called W3C HTML/DOM standards and browser compatibility are our Gordian Knot equivalent. It has not been possible for anyone to unravel this perplexing knot.

Well, turns out there's a splendid Alexander the Great style of solution to this problem - the Adobe Flex RIA web application development approach.

With Adobe Flex I get nice AJAX style I/O for making asynchronous request to the server-side, but I also get server-side push by two or three different means of solution. One way that works great and is very simple is to use Flex XmlSocket bi-directional messaging. Just use the Apache MINA java nio framework on the server-side to handle the persistent socket connections. Presto - server side push of events is now possible.

One can then use Flex MXML/ActionScript3 properties, events, and data binding to process events that are pushed from the server to the client.
2 . At 5:28 PM on Dec 31, 2007, Tom wrote:
  Click to reply to this thread Reply

Re: Server-sent events: the web upside down

Well, turns out there's a splendid Alexander the Great style of solution to this problem - the Adobe Flex RIA web application development approach.

If that's your solution, why not go all the way and adopt an all-Microsoft solution?

I'll tell you why: Adobe Flex is an attempt to do an end-run around current web standards, tools, and practices, and it deserves to fail just like all the other such attempts. Adopting it would be like handing the web to Adobe on a silver platter.

W3C HTML and DOM work and are widely supported by tools from many vendors; no single vendor has an advantage or can change direction unilaterally. That's a good thing.

If you want server-side push for AJAX applications, there are already solutions for that. If you really require something different (I don't), argue for it in the W3C, don't try to tell us that we should all retool.
3 . At 2:18 AM on Jan 1, 2008, Roger Voss wrote:
  Click to reply to this thread Reply

Re: Server-sent events: the web upside down

Over and over the sanctimonious HTTP/web-standards crowd tries to claim how doing such and such is not possible within the context of their precious standards. This naysayer crowd does serve one useful purpose: To the extent some folks listen to them, then that gives one a competitive advantage to go on and pass them by.
4 . At 11:29 AM on Jan 1, 2008, Tom wrote:
  Click to reply to this thread Reply

Re: Server-sent events: the web upside down

then that gives one a competitive advantage to go on and pass them

Are you joking? People who bet on Java applets and ActiveX got burned big time. Those technologies lost to Ajax not because of "sanctimony" but because real-world programmers decided they didn't get the job done. I don't see why Flex should be any different, and I doubt you can come up with a good technical and economic argument.
5 . At 3:11 PM on Jan 1, 2008, Roger Voss wrote:
  Click to reply to this thread Reply

Re: Server-sent events: the web upside down

SVG was the W3C attempt for vector graphics for the web. Microsoft doesn't play ball with the W3C, however, and so IE hasn't had native support for SVG. Yet even after the inroads of Firefox, IE remains the dominant web browser that developers must still accommodate.

So much for the so-called W3C standards providing for a uniform web development target on all OS platforms and browsers of note.

"Oh, but you can have your users install a SVG plugin on IE browsers."

Yeah, and if I get into the game of having users install a plugin, then I might as well have them install a Flash player plugin (which they already have anyway in order to watch youtube videos) to where they can run my Flex applications. Then I not only get a uniform development target across all OS platforms and browsers of note, I also get to use the Flex and Flash capabilities which are superior to ancient old school W3C web standards, and give rise to the new breed of RIA web application.

The other thing W3C/web-standards folks don't grasp is that their whole programming model is a monstrosity. Flex has become this wonderful opportunity to break out of that morasses of what has to be the worst programming model in the history of computer science.

> I don't see why Flex should be any
> different, and I doubt you can come up with a good
> technical and economic argument.

The genie is already out of the bottle. Customers are loving our Flex-based web apps.

The technical argument is that my dev staff produces superior web software via using a more productive programming model.

The economic argument is that the applications we create for customers are markedly superior in characteristic to conventional AJAX web apps (while being more cost effective for us to produce). Additionally, it is much more economically feasible now for us to produce a solution that runs well across Windows, Mac OS X, and 32-bit Linux OS, as well as IE, Mozilla/Firefox, and Safari browsers.

I could get into how the RIA + SOA approach is also way better than the typical web framework on the server-side approach, but that warrants a completely different discussion thread. It is, however, one of the biggest attractions to the whole Flex RIA web app model.
6 . At 8:48 PM on Jan 1, 2008, Tom wrote:
  Click to reply to this thread Reply

Re: Server-sent events: the web upside down

SVG was the W3C attempt for vector graphics for the web. Microsoft doesn't play ball with the W3C, however, and so IE hasn't had native support for SVG.

If Microsoft is creating obstacles for SVG, do you think they are just going to let Flex take over? If Flex looks like it might win, Microsoft will most likely start supporting and advocating SVG because to them, SVG is still better than an Adobe technology.
7 . At 9:35 PM on Jan 1, 2008, Roger Voss wrote:
  Click to reply to this thread Reply

Re: Server-sent events: the web upside down

> If Microsoft is creating obstacles for SVG, do you
> think they are just going to let Flex take over? If
> Flex looks like it might win, Microsoft will most
> likely start supporting and advocating SVG because
> to them, SVG is still better than an Adobe
> technology.

Heck, Microsoft is going head on against Flex by coming out with Silverlight. They too finally realized that Adobe - before any other company or entity (such as standards bodies) - has envisioned the next generation of Internet applications and made good on delivering a platform for that vision. So Microsoft is out to play the me-too card.

But vector graphics is just one small piece of the puzzle of what comprises the new generation of RIA web apps. At this point, with the Flex RIA web app phenomena well underway, Microsoft's IE intrinsically supporting SVG would be a non event.
8 . At 1:25 AM on Jan 2, 2008, Tom wrote:
  Click to reply to this thread Reply

Re: Server-sent events: the web upside down

You know, tell you what: why don't you actually show us your "RIA web apps" and give us some details on how long it took to develop them, how much it cost, what kinds of user studies you have been doing, how much code there is, etc.? Then we can judge for ourselves how good your Flex apps really are.
9 . At 12:13 PM on Jan 2, 2008, Brian Sayatovic DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Flex vs. the world

I've not tried Flex, but I certianly understand the concept. And as others have pointed out, there are other Flex-like alternatives (Silverlight from MS, and I believe Laszlo). Some have even suggested Flash be an application platform (witness FlashLite on newer mobile phones).

But because each platform has large groups of supporters that spit venom at the others, there will never emerge a cohesive not de facto standard. Look at HD-DVD vs. BluRay. Who wins? No one. Who loses? The consumer.

That is where standards become helpful.

While I like the concept of Flex, I certainly don't want to see a Flex-dominated world. Flex is a necessary step to get the world to recognize an opportunity. Hopefully a standard will emerge.
10 . At 12:54 PM on Jan 2, 2008, Tom wrote:
  Click to reply to this thread Reply

Re: Flex vs. the world

Hopefully a standard will emerge.

The standard has already emerged: it's Ajax and Canvas, and their future enhancements. I doubt there will be anything else in the next decade. Either you support that, or you go with the proprietary choice; I don't see a third option.
11 . At 1:00 PM on Jan 2, 2008, Andy Tripp DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: Flex vs. the world

> But because each platform has large groups of
> supporters that spit venom at the others, there will
> never emerge a cohesive not de facto standard. Look
> at HD-DVD vs. BluRay. Who wins? No one. Who loses?
> The consumer.
>
> That is where standards become helpful.

Huh? Standards (at least language standards defined by standards bodies) have no trouble at all being produced when there are multiple platforms, each with supporters "spitting venom at the others". In fact, that's the whole purpose of standards: to bring these warring factions together.

As for "who wins" in the blu-ray vs. HD-DVD wars, Microsoft wins: http://hardware.slashdot.org/article.pl?sid=07/12/05/1317200

>
> While I like the concept of Flex, I certainly don't
> want to see a Flex-dominated world. Flex is a
> necessary step to get the world to recognize an
> opportunity. Hopefully a standard will emerge.

I assume you mean an official standard here, not a defacto standard, because Flex is the defacto standard. As for an official standard emerging around Flex (or any other programming language), I don't see any reason to hope for an official standard to emerge. What good have standards done us for C, C++, HTML, CSS, and Javascript? None. In each case, the standard just specifies some basic common functionality, and then various implementations make various efforts to come close. The main thing these standards have done, though, is to allow MS to get a foothold so that they can later dominate and then ignore the standard.
Andy Tripp, CTO and Founder Jazillian - Legacy to 'natural' Java.
12 . At 1:01 PM on Jan 2, 2008, Will Hartung DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: Server-sent events: the web upside down

> The technical argument is that my dev staff produces
> superior web software via using a more productive
> programming model.

No, they don't produce "Web" software. They produce client server software that's running in the flash container, that just so happens to be deployed in a web browser. And, no, I'm not splitting hairs, it's an important point.

I would never argue that a large Active-X component, or a large Java Applet would be considered "web software". By you definition, Java Web start is "web software". And it isn't.

Your "web" software, for example, won't run on the iPhone -- which doesn't support flash (nor Java, nor Active-X, nor Silverlight). It DOES, however, support a pretty good web browser.

Now you'll say "well, the iPhone isn't our target platform". And that's fine, but neither is the web your target platform. Your target platform is a Flash container.

The modern JS libraries are working to keep the competing browsers usable for "web" applications. The "web" today is basically about as portable as Unix was back in the day. That is, it's MOSTLY portable, but not 100%.

It'll never be 100%. But it will always strive to be as compatible as practical because the market is basically demanding it be so.

Flex and Flash handily punt on that problem of cross browser compatibility (though, of course, you still have version dependence on your runtime...your apps don't run on Flash 5, eh?), but so do other technologies (Java for one). But make no mistake, Flash is NOT a "web application". It's a "fat app" plain and simple, they just happen to deploy a bit easier than competing technologies.
13 . At 1:08 PM on Jan 2, 2008, Will Hartung DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: Flex vs. the world

They need to get the ball rolling and get Text in to Canvas. That's a REALLY large limitation to the adoption of Canvas. There are workarounds, but boy are they a REAL pain.

And now with SVG support in Safari and Firefox, the only browser not supporting SVG is IE...and it doesn't support Canvas (natively) either...so...

Granted, there are canvas libraries that give us canvas-like support for IE.

Mind, I'm still a fan of Canvas. I think there is room for both Canvas and SVG.
14 . At 8:55 AM on Jan 3, 2008, Derek Smith wrote:
  Click to reply to this thread Reply

Re: Server-sent events: the web upside down

Too bad this thread has deteriorated into a conversation about flex vs. standards. I was actually interested in the server-sent events stuff.
http://www.programmersbible.com - Online resource for programmers

thread.rss_message