[Standards] Network IO best practices

Ivan Vučica ivan at vucica.net
Sun Jun 10 13:34:17 UTC 2018


If you were waiting for CR/CRLF, you would similarly be reading “one byte
at a time” (probably buffering first and then seeing whether the buffer
contains a newline?).

What you are looking for are streaming XML parsers. You can do this in Go
with encoding/xml; you will get individual tokens which you can reconstruct
into stanzas. It’s easy as encoding/xml’s streaming decoder takes in an
io.Reader. You do need to keep track of where you are in the tree.

Having said this, this is how I toyed with writing a server. (Nothing
released, or for that matter, clean.)

But the existing client libraries that I used weren’t that bad, and I think
it makes sense to see if you can improve some of them rather than write a
new lib from scratch. Just as an example, ProcessOne seems to have been
thinking about this well and they put together a basis for a good lib.

On Sun 10 Jun 2018 at 06:10 Daniel Corbe <dcorbe at gmail.com> wrote:

> Hi,
>
> First time implementor of anything XMPP-related, much less outside of the
> use of a library for dealing with XMPP.
>
> The chosen language here is Go and the few XMPP libraries that exist in
> our
> world are hilariously incomplete.   So I’m stuck implementing a library
> for
> my application from scratch.
>
> So here goes my question.
>
> I’m watching my XMPP client talk to a server, and there doesn’t seem to
> be
> any delineation between stanzas.   It’s just a byte stream of XML.   No
> CR,
> CRLF or LF to indicate that one side of the conversation is finished
> sending messages.
>
> How do people typically deal with this in other languages?
>
> Because it would seem to me as if one would need to read the entire
> stream
> one byte at a time and wait for valid input before passing the message
> off
> to a parser.   IE, I’m looking for that final closing > before I can reply.
>
> Is there a better way to go about it that isn’t going to incur a massive
> performance penalty?
>
>
> _______________________________________________
> Standards mailing list
> Info: https://mail.jabber.org/mailman/listinfo/standards
> Unsubscribe: Standards-unsubscribe at xmpp.org
> _______________________________________________
>
-- 
Sent from Gmail Mobile
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.jabber.org/pipermail/standards/attachments/20180610/68eeba79/attachment.html>


More information about the Standards mailing list