XML and streaming from/to Tigase

Submitted by taroza on Thu, 2008-05-08 14:12.

Reading RFC3920 for XMPP I realized that the communication c2s is not really done using pure XML:
1. Client sends start of the stream: <stream>
2. ....communication....
3. Client sends end of the stream: </stream>

This means that the client, reading a packet will have to parse a string, instead of parsing XML. Or am I getting something wrong?

However, I hope that when the communication is established and two entities are exchanging data, they are actually exchanging XML (stanzas). Is that right?

Before looking at XMPP I always thought that it works similarly to Web services, i.e. exchanging well-formed XML messages.

Could anyone clarify these concerns a bit. Thanks.

Evaldas

Trackback URL for this post:

http://www.tigase.org/trackback/1386
kobit's picture
Submitted by kobit on Thu, 2008-05-08 21:34.

Yes you are absolutely correct here.

  1. It is one big well-formed XML document except the stream restarts I mentioned before and except the fact that the connection is quite often terminated without sending closing stream tag.
  2. I know that many projects use different XML parser to handle the issue of processing streamed XML data. As far as I know there are even dedicated XML parsers for XML streams. When I was starting my project I couldn't find any good and lightweight XML parsers for my needs and this is why I implemented own XML parser for XMPP protocol.
  3. Assumption that only the first packet would be non-XML (missing closing tag) is only partially correct however. Look at the stream restarts I mentioned before... There are normally 2 stream restarts during initial handshaking. They might be removed from the protocol in the future but for now they are mandatory.
  4. Yes it is challenging, but it is also a great fun... :-)

Would you like to join Tigase project? :-)


Submitted by taroza on Thu, 2008-05-08 21:00.

Yes, it really looks like it's a big well-formed XML document... But technically you need some kind of a streaming parser to be able to parse such a fancy non-ending XML document :)

Anyway. Can we say (is it according to XMPP) that only first packets will be non-XML? I mean the first thing a client receives from server is
<stream>....; are the subsequent packets well-formed XML snippets? Meaning that whenever stream has started, every subsequent communication will be ... or , etc.?

All this XMPP stuff is really challenging:)

Evaldas

kobit's picture
Submitted by kobit on Thu, 2008-05-08 14:58.

Well, you are right and you are not right ;-)

In simple words: The whole communication between the XMPP client and the XMPP server is like one huge XML document. The root element is <stream> while all stanzas are child elements of the root element.

So in theory the client and the server exchange well formed XML document (stream). And actually it is also very similar to web services although it doesn't look like this at first look. This is because there is one fundamental difference between web services and XMPP protocol:

Web services normally establish short-term connection between entities, exchange data and close the connection. Normally during the connection life exchanged data form correct XML document and so more important communication is synchronous - one side sends request and then waits for a response.

If you look at XMPP you could see it as a very long-term living web service with connection lasting for hours or days and during the connection life the exchanged data form correct XML document BUT the communication is asynchronous which means at any given time there might be a packet arriving at both ends.

There is one issue however which destroys the well-formed XML stream in the XMPP protocol - stream restarts. As far as I know XSF works now on removing stream restarts from the protocol.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.