[jdev] TCP Packet Construction

JD Conley jconley at winfessor.com
Fri Nov 5 11:50:18 CST 2004

I would also recommend you have a look at the available libraries.  A
lot of people have written Jabber/XMPP support and done all this


JD Conley

> -----Original Message-----
> From: Jon Phillips [mailto:jon at rejon.org]
> Sent: Friday, November 05, 2004 12:06 AM
> To: Jabber software development list
> Subject: Re: [jdev] TCP Packet Construction
> First of all thanks for your wonderful insight!
> Heiner Wolf wrote:
> > Hi,
> >
> >
> >>I interested to know if there are any good resources, documents, or
> >>source code I could look at to see how to properly receive
> >>packets from a jabber server like jabberd (which I am using) via TCP
> >>then how to receive and reconstruct the entire packet.
> >
> >
> > When you deal with TCP as in the case of Jabber, then you must not
> in terms of 'packets'. Both parties will receive a stream of bytes.
> they send chunks of data on the connection, there is no guarantee that
> receiver gets the data in the original chunks. The only guarantees
> TCP gives are 1. that the data will arrive or you get an error 2. the
> order will be retained. Again: the receiver might get the data in
> different 'packets'.
> >
> >
> >>I'm using Visual Studio .net and WINSOCK to do connection and
> >>receiving. Right now I have a working client that receive packets
> >>are 8129 bytes, but these packets might not contain the full
> >>This problem gets worse with more traffic.
> >
> >
> > What you must do is: forward every piece of data to the protocol
> In this case it is an XML parser. The XML parser must be able to parse
> 'incomplete' XML and tell you about the structure before the main
> tag is closed. People call it a SAX parser as opposed to DOM parsers.
> need a SAX parser. You feed it with every byte that comes from the
> connection. There is virtually nothing between the read() system call
> where you get data from the connection and the parse() where you
> the data to the parser. The parser will consume the bytes. The parser
> tell you when a first order tag is finished. That would be something
> a <message/> or <presence/> inside a <stream:stream>. If this happens
> you can analyze the first order tag. That's then called a stanza in
> terms. In XML terms it is just the first order sub tag of the XML
> tag.
> What parser would you recommend? I'm looking into expat. I was using
> tinyXML, but it doesn't seem to fit the bill you are describing...
> >
> >
> >>What is the best way to construct entire jabber server packets into
> >>comlete packets/message. For example, the server might send a user's
> >>message in xml, and because of web traffic the complete message
> >>not arrive in teh received 8192 bytes...
> >
> >
> > I reiterate, because this is important: this is TCP. There are no
> messages. Your network API will give you multiple bytes at once. This
> looks like a message. You don't care. You handle all data to the XML
> parser. The parser will tell you when stanzas are complete. You are
> probably testing in your lab. Over the wide internet you might even
> smaller pieces of data at once (like 500 bytes). Stanzas might be
> badly. There might be even the last '>' missing. Don't look at the
> directly. Let the XML parser look. It will tell you when a stanza is
> complete.
> >
> >
> >>Other than this problem, my custom jabber client for this game,
> >>gopetslive.com is going pretty well.
> >>
> >>Any help or code sample or pointers would be much appreciated.
> >
> >
> > hw
> > --
> > Dr. Klaus H. Wolf
> > bluehands GmbH & Co.mmunication KG
> > http://www.bluehands.de/people/hw
> > +49 (0721) 16108 75
> > --
> > Jabber enabled Virtual Presence on the Web: http://www.lluna.de/
> > Open Source Future History: http://www.galactic-developments.com/
> > _______________________________________________
> > jdev mailing list
> > jdev at jabber.org
> > http://mail.jabber.org/mailman/listinfo/jdev
> >
> >
> --
> Jon Phillips
> KOREA.PH.010.3140.7483
> USA.PH.858.361.2811
> jon at rejon.org
> http://www.rejon.org
> Inkscape (http://inkscape.org)
> Open Clip Art Library (www.openclipart.org)
> CVS Book (http://cvsbook.ucsd.edu)
> Scale Journal (http://scale.ucsd.edu)
> _______________________________________________
> jdev mailing list
> jdev at jabber.org
> http://mail.jabber.org/mailman/listinfo/jdev

More information about the JDev mailing list