Datasheet
XMPP Stanzas
9
Bare JIDs for clients are somewhat special, because the server itself will handle stanzas addressed
to a client’s bare JID. For example, a message sent to a client’s bare JID will be forwarded to one or
more connected resources of the user, or if the user is offline, stored for later delivery. Stanzas sent
to full JIDs, however, are usually routed directly to the client’s connection for that resource. You
can think of bare JIDs as addressing the user’s account as opposed to addressing one of the user’s
connected clients.
XMPP STANZAS
Work is accomplished in XMPP by the sending and receiving of XMPP stanzas over an XMPP stream.
Three basic stanzas make up the core XMPP toolset. These stanzas are
<presence>, <message>, and
<iq>. Each type of stanza has its place and purpose, and by composing the right kinds of quantities
of these stanzas, sophisticated behaviors can be achieved.
Remember that an XMPP stream is a set of two XML documents, one for each direction of
communication. These documents have a root
<stream:stream> element. The children of this
<stream:stream> element consist of routable stanzas and stream related top-level children.
Each stanza is an XML element, including its children. The end points of XMPP communication
process input and generate output on a stanza-by-stanza basis. The following example shows a
simplified and short XMPP session:
<stream:stream>
<iq type=’get’>
<query xmlns=’jabber:iq:roster’/>
</iq>
<presence/>
<message to=’darcy@pemberley.lit’
from=’elizabaeth@longbourn.lit/ballroom’
type=’chat’>
<body>I cannot talk of books in a ball-room; my head is always full of
something else.</body>
</message>
<presence type=’unavailable’/>
</stream:stream>
In this example, Elizabeth created an XMPP stream by sending the opening <stream:stream>
tag. With the stream open, she sent her first stanza, an
<iq> element. This <iq> element requested
Elizabeth’s roster, the list of all her stored contacts. Next, she notified the server that she was online
and available with a
<presence> stanza. After noticing that Mr. Darcy was online, she sent him
a short
<message> stanza, thwarting his attempt at small talk. Finally, Elizabeth sent another
<presence> stanza to inform the server she was unavailable and closed the <stream:stream> ele-
ment, ending the session.
You have now seen an example of each kind of XMPP stanza in action. Each of these is explained in
more detail, but first, you should learn about what properties they all share.
40718c01.indd 9 11/30/09 8:23:49 PM