[jdev] My outgoing jabber packet

Anthony Ortiz anthonypaulo at gmail.com
Fri Mar 11 20:29:40 CST 2005

Hi Joe!!

I think I've taken both of these into account already... For example :

In the event of a fragmented stanza :
[packet 1]
<iq type='result' id='auth1'>
  <query xmlns='jabber:iq:auth'>

[packet 2]

It will get packet1, get the root element (<iq>), and look for its end
tag (</iq>). If the end tag is not found, then it will keep reading
the stream until it finds it, which it does in packet2. Ditto in the
event of the stanza being longer than the MTU size :

[packet 1]
<message from='fromid' to='toid' id='someid'>
some long text here

[packet 2]
continuation of long text here

<message from='fromid' to='toid' id='someid'>
... and that's all folks.

Here's a slightly more detailed flow of events :

1) get packet
2) get the root element (<message>), and look for its end tag (</message>). 
3) tag not found, save to content buffer (in order to concatenate with
next packet)
4) get packet (we're actually going back to step1 here)
5) content buffer contains data, so append packet to current saved
content buffer
6) end tag found in packet, so process content buffer (here is where
you process the entire message stanza)
7) truncate content buffer to contain only any remaining stanzas (in
this case the other message in packet2; the one containing "... and
that's all folks.") and goto step 2

Does this answer your question? The only case where I see this not
working is if the Jabber server sent partial fragments from different
senders :

<message from='JoeSchmoe' to='toid' id='someid'>


<body>... and that's all folks.</body>

But I *really* doubt that the Jabber specification will allow breaking
up xml fragments this way since there's no way to tell which packet
belongs to who. I thought about this possibility before writing my
client and couldn't find any information regarding it on the web, but
I made this assumption and stuck to it since it's the only way that
made sense. I hope I'm right here, cuz if I'm not then I would be
extremely curious to know of *any* solution to deal with the

Hope this answered your questions!! I'll check Jabber-Net to see what
they're doing.



p.s. I check for start/end tags via a regular expression with some
added optimization here and there... very fast!

> This won't work, if any of your stanzas get fragmented, either by a
> network element, or because they are longer that one MTU.  Either of
> these can happen at any time, but won't show up in testing with small
> packets on a local machine.
> Jabber-Net now has a comprehensive workaround for this problem, in the
> form of a port of portions of James Clark's XP parser from Java to C#.
>  XP can deal with partial stanzas quite nicely, and as a side effect,
> is very fast.

More information about the JDev mailing list