File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes AJAX,WebSockets, XMPP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "AJAX,WebSockets, XMPP?" Watch "AJAX,WebSockets, XMPP?" New topic

AJAX,WebSockets, XMPP?

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
Imagine a online-game with two players (clients).

What is the best technique to guarantee
that these two players are able to play interactivately,
that means player 1 sees the changes of player 2 immediately and both can react simultaneously ("real-time communication").

I guess, AJAX (DWR, Direct Web Remoting) is too slow.
So should I go for WebSockets or XMPP or JMS(Java Messaging Service) or SERVLET API 3.0 (with its "COMET-API")
or is there another techinque which is the right thing for that kind of web-application?
David Newton

Joined: Sep 29, 2008
Posts: 12617

That's a whole bunch of acronyms that are only vaguely related to each other, and if it's a *web* app, a couple aren't even applicable unless you're using an applet.

Have you *proven* that Ajax doesn't work they way you need it to?

Define "immediately", since it's *obvious* "immediate" is impossible, regardless of *any* method you use.
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
Hello David,

actually I am trying/learning WebSockets by using JETTY-Servlet-Container
(which has built-in support for WebSockets).

Unfortunately, there is no XMPP-Server-Support for any Servlet-Based-Container
(such as Tomcat/Jetty, JBoss, Glashfish,..), so I need to have an additional XMPP-Server
( running simultanously with my JETTY.
That is annoying. So I guess, I do not use XMPP and use WebSockets instead.

Have you *proven* that Ajax doesn't work they way you need it to?

I have been using ajax quite often without problems.
However, I want to give a try to use WebSockets or XMPP instead of Ajax (or Comet)
as I want to have a web based real-time-application.


Jonas Jacobi

Joined: Apr 04, 2006
Posts: 25
Hey Nimo,

I believe there is a misunderstanding here. WebSockets is not a replacement or a better Ajax. You should look at WebSockets the same way you look at a TCP socket. Instead of coding against the WebSocket APIs directly, you should use a protocol client such as XMPP that has been built on top of the WebSocket API. This will let you communicate directly with the XMPP server from the browser via a WebSocket-enabled server (if the server has been properly designed).

A demo example of how this can be done you can see here - This site shows how you can use XMPP over WebSockets to communicate with Google Talk (hint: use your Google account to login and chat).

Or, you can read this article - - which covers this topic well.

Author Pro JSF and Ajax

Author: Pro JSF and Ajax: Building Rich Internet Components, Apress
I agree. Here's the link:
subject: AJAX,WebSockets, XMPP?
It's not a secret anymore!