Wednesday, April 12th, 2006
DWR 2.0: Reverse Ajax
Joe Walker of DWR fame writes in:
We’ve just released DWR version 2.0 milestone 1 - This is probably the biggest release we’ve ever done in terms of new features.
The big new feature is Reverse Ajax: DWR 1.x allowed you to asynchronously call Java code from Javascript. DWR 2.0 builds on this to allow you to asynchronously call Javascript code from Java. Reverse Ajax makes writing interactive applications much easier. Reverse Ajax makes writing interactive applications much easier. It can use polling or Comet (long-lived HTTP) queries.
Our ‘chat’ example contains Java code like this:
// Get the current pageWebContext wctx = WebContextFactory.get();String currentPage = wctx.getCurrentPage();// ’messages’ is a Listof recent messages for a browser to display // Java objects converted to Javascript have a declaration and a declared variable name.OutboundVariable ov = wctx.toJavascript(messages);// Loop over all the users on the current pagefor (ScriptSession otherSession : wctx.getScriptSessionsByPage(currentPage)) {otherSession.addScript(ov.getInitCode() );otherSession.addScript(“receiveMessages(” + ov.getAssignCode() + “);” );// receiveMessages is a Javascript function that displays the current messages}In essence we are looping over all the users on the current page and sending them some Javascript to update their display. The Javascript is even simpler. You just turn polling on:
DWREngine.setPolling(true);Other new features include cross-domain Ajax, an automatic signatures element for JDK5 generics and a bunch of other changes. For more information see the detailed release notes, or go straight to the download area












Maybe I am just not understanding this concept right. But I do not see how this can be called “Reverse AJAX” when all it seems to do is have the client javascript keep calling the server, so that when the server has a new update the client can receieve it.
If thats all this does then I don’t really think its “Reverse AJAX.” Its just a client-server events system, but like everything else in the web 2.0 world we have to give this an improper name so that way it seems revolutionary or cool.
I would think that the only way to do “Reverse AJAX” is to use a socket connection back to the server. No?
pplante — you aren’t quite getting it right. Their system keeps a socket open indefinately. Think of each client as slowly loading content from the server and displaying it progressively. Except that the data can trickel in over hours. Then you have a server process-to-process communication so that all the other processes that you might want to notify start downloading a more information. This won’t work with PHP, etc., since they don’t have process-to-process communication, and it won’t work with HttpXmlObject (as far as I know, since most don’t implement multi-part-mime needed to make this work), but it will work with Java and Iframes.
I’m using sockets for my realtime systems. Currently I’m using Flash8 (AFLAX). What I’m running into is that a lot of MSIE users can’t get Flash 8 to install. About 1 out of 5 right now. I tried some Java applets to do sockets, but I couldn’t get that to work across platforms too well (again MSIE).
[...] I see that a new version of DWR has been released. And it sounds very familiar for some reason. [...]
Developing and deploying eLearning encounters the same types of hurdles. You *want* to use the latest and greatest technology but some of your audience just doesn’t have it…nor are they able to install it. The ‘live’ connection between the eLearning course and the server is typically through a java applet that has an open socket connection to the server and a javascript API that makes calls to the applet for storing/retrieving information. The trouble is the JRE. If the user has a version that’s too old, they have to download and install a new one, etc etc.
I feel your pain….
To pplante - As mentioned in this post, both polling and Comet are sopported. If you use the polling mode, it means you keep requesting server at some interval. That’s the way you said like everything in the web2.0 done. But if you use Comet mode, then it’s like server-push technique. Please refer to Comet
So… “the process of using either polling or a long lived connection (Comet)”… why the need to rename it as “Reverse AJAX” other than the cool sound of it? ;)
A new concept - REVERSE AJAX
æ–°ã—ã„コンセプトを勉強ã—ãŸã€‚
Reverse Ajax
Comet Queryies
Reverse Ajaxã®æ„味ã¯Ajaxianã‹ã‚‰ã®èª¬æ˜Žã‚’見れã°åˆ†ã‹ã‚‹ã¨æ€ã†ã€‚
The big new feature is Reverse Ajax: DWR 1.x allowed you to asynchronously call Java code from Java…
Has anybody got this working? If yes, do you use “polling” or “comet”
setting? I don’t see any documentation on usage of these except for Chat example which uses “polling” setting. As per my experience, it sometimes work, sometimes doesn’t - pretty unreliable.
So far, I have not been able to get it working with “_pollComet”. Any body had better luck than me? Pls let me know if so.
Links: 5-17-2006
Ajaxian » DWR 2.0: Reverse Ajax Prediction: reverse ajax (I prefer rajax) will be big… and hard on servers. (categories: ajax rajax )…
Reverse Ajax includes polling and comet as well as a technique which allows results to piggyback on other requests to the server. In this article I use love, a French lesson and a donkey to illustrate the 3 main techniques for facilitating server updates to the browser as used by Reverse Ajax. Enjoy!
It says DWR2.0 uses Comet as default, but when I test the Chat demo I find that it also polls the server although at a relative long interval. I am not very clear about how DWR implement the Comet mechanism, is Comet means a long interval polling or a tradeoff between polling and long-lived http connection?
[...] http://ajaxian.com/archives/dwr-20-reverse-ajax [...]
so..can the dwr provide me with the true push just like lightstreamer?i don’t want my client keep requesting my server for new updates