OpenP2P.com    
 Published on OpenP2P.com (http://www.openp2p.com/)
 See this if you're having trouble printing code examples


XML Messaging with Jabber

by Peter Saint-Andre
10/06/2000

Discussions of XML can often seem dry, abstract, and even hopelessly arcane. (Have you read the XML Schema spec lately?) So it can be refreshing to look at a powerful (even fun) application that's built on XML. One such application is Jabber, an open source instant messaging and presence system that is beginning to garner a lot of attention from the open source community and large corporations alike.

Eric S. Raymond's first lesson of open source software development declares that "Every good work of software starts by scratching a developer's personal itch." That was certainly the case with Jabber. Jeremie Miller, the founder of the Jabber.org project, got sick of using four or five applications to keep in touch with friends on different instant messaging (IM) systems and to monitor various IRC channels. So he started to think about building a cross-platform, open source IM system that would speak to all the other messaging systems.

From the beginning of the project in early 1998, Jeremie resolved that Jabber would stand apart from existing IM systems by being based on a foundation of XML. Indeed, XML is not an afterthought or a cool buzzword in the Jabber world, but, as we shall see, simply the way things are done.

The basic architecture of Jabber is extremely similar to that of e-mail: there is a network of distributed servers, with a user connecting to their host server and servers transferring messages through one or more hops to a destination server for delivery to the intended recipient. From the perspective of the user, Jabber IDs are identical in form to e-mail addresses (in my case stpeter@jabber.com), and one registers with a Jabber server in much the same way that one creates an account with an ISP.

Related Articles:

Jabber Works: Here's How

Peer-to-Peer Makes the Internet Interesting Again

News -- view a week's worth of Jabber news via Meerkat.


More from the P2P DevCenter Previous Features

The server perspective is somewhat more complicated -- and in fact, this is intentional, because the relative complexity of the server offloads responsibility from the clients, thus making it easy to write Jabber clients for a wide variety of platforms. In essence, however, the server is made of two basic components: the core Jabber libraries and optional "transports."

The core libraries handle communications within the Jabber system. An example is when I send a message from my Jabber account to a friend who is also using Jabber. In this case, all the messaging occurs in the format of the Jabber's open XML protocol, so the communications are "native" to Jabber. Although there is a lot of code that makes this happen, in a way it is relatively simple.

The transports translate Jabber XML into and out of what we might think of as "foreign" protocols. An example is when I chat with a friend who's using another instant messaging system (such as AIM, ICQ, or MSN). Another example would be when I use Jabber's groupchat facilities to join an IRC channel, as shown below:

IRC over Jabber

Jabber screen shot.

IRC over Jabber.

It's in the world of transports that some of the "black magic" of Jabber comes into play, especially when the foreign protocol is not well-documented. When you use Jabber to connect to non-Jabber systems, it is as if the relevant transport is "masquerading" as you on the foreign system. When you register with the transport, you tell it about your user information on the foreign system, and in the future it acts on your behalf with that system, sending and receiving messages and presence information in that foreign protocol. The result is that your friends on (let's say) ICQ think they're communicating with you on ICQ when in fact you are using Jabber, and specifically Jabber's ICQ transport, to speak the language of ICQ. In this way Jabber is somewhat like a universal translator, although at present Jabber is not "universal," since transports do not yet exist for all messaging systems. (And no, we won't get into the politics of interoperability in this article!)

As noted, within the Jabber system itself, all communications take place in XML. Specifically, communications between the client and the server occur over persistent TCP connections using XML streams that go through port 5222 (or 5223 when using SSL). Here is what the XML might look like (you'll notice that there are actually two streams: one from the client to the server and one from the server to the client):

SEND:   <stream:stream
SEND:      to='jabber.org'
SEND:      xmlns='jabber:client'
SEND:      xmlns:stream='http://etherx.jabber.org/streams'>
RECV:   <stream:stream
RECV:      xmlns:stream='http://etherx.jabber.org/streams'
RECV:      id='39ABA7D2'
RECV:      xmlns='jabber:client'
RECV:      from='jabber.org'>
      (XML for user session goes here)
SEND:   </stream:stream>
RECV:   </stream:stream>

All of the user session data transferred between client and server is contained within three basic Jabber XML elements:

  1. presence -- this indicates whether a Jabber user is online or not, and if so in what state (available, away, etc.)
  2. message -- this is used to hold the messages that are passed from one user to another
  3. iq (short for info/query) -- this is used to search user directories, update contact lists, and such

Here is what a simple presence element might look like:

<presence
   from='ericmurphy@jabber.org/notebook'
   to='stpeter@jabber.com/Gabber'>
<status>Online</status>
</presence>

And here is what a simple message element might look like:

<message
   to='ericmurphy@jabber.org/notebook'
   type='chat'>
<body>hey, how's the Mozilla client coming along?</body>
</message>

In addition to these basic elements (which themselves support a wide range of information exchange), Jabber XML is highly extensible, and it is easy to add new namespaces for things like vCard XML, RSS for headlines, stock tickers, or structured data for custom applications that run on top of Jabber. In essence, Jabber can function as something approaching a generalized XML router, sending any XML from one point to another, instantly.

"Well that's interesting," I hear you saying, "But what kind of fun stuff can Jabber do for me now?" The existing applications of Jabber are mostly centered around person-to-person messaging: individual and group chat, IRC, and connecting to other IM systems (currently AIM, ICQ, MSN, and Yahoo!), although Jabber also supports handy functionality like receiving news headlines via RSS:

Headlines in Jabber.

Headlines in Jabber.

Future applications of Jabber will include:

As noted, the Jabber system was designed so that clients would be simple to create. This design philosophy has yielded good results, since clients are currently available for Linux/Unix, Windows, Macintosh, and several other platforms. In addition, efforts are underway to enable Jabber access for handheld devices, cell phones, and all manner of embedded systems. And, not to ignore the Web, several clients are in the works that use Java applets, Mozilla integration, and plain old HTML/JavaScript to enable Jabber communications over HTTP, which will be especially appealing to users behind restrictive firewalls.

Main Jabber websites:

jabber.org -- open source project site, mainly geared to developers.

jabber.com -- a commercial entity offering Jabber consulting, customization, hosting, etc.

jabbercentral.com -- a news and support site focused on end users.

Useful documentation:

Jabber Technical Whitepaper -- lots of juicy technical info.

Jabber Programmers Guide -- even more juicy technical info.

Jabber RFC -- the Jabber project's submission to the IETF.

Speaking of firewalls, the Jabber developers definitely have issues of privacy and security at the top of their minds. For instance, your presence on Jabber is available only to those whose subscriptions you approve. In addition, Jabber supports SSL in communications between client and server, and PGP/GnuPG is being built into several Jabber clients (although it is not yet available at this date). Finally, the ability to run your own server (and mess with the source code if you want to) separates Jabber from the raft of proprietary IM systems out there, and is a big selling point with security-conscious individuals and organizations across the net.

At present the Jabber server runs on Linux/Unix only, and the installation process is, shall we say, not as simple as it could be. However, the forthcoming 2.0 server will be much improved in this and other respects (including much more robust scalability). Despite the setup challenges, there are currently over 1000 Jabber servers running throughout the world, with more coming online every day at a seriously accelerating rate. While Jabber is still a young technology, open source software is well-known for spreading like wildfire -- and the Jabber messaging platform may be experiencing the same kind of explosive growth that e-mail servers did in the early days of the Web. Only time will tell whether Jabber's open technology fulfills its promise to become a ubiquitous system for real-time, XML-based communication.

Peter Saint-Andre has been contributing to the Jabber/XMPP developer community since late 1999 and is currently Executive Director of the XMPP Standards Foundation.


Return to the P2P DevCenter.

Copyright © 2009 O'Reilly Media, Inc.