[Standards] Network IO best practices
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:
> 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
> world are hilariously incomplete. So I’m stuck implementing a library
> 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
> any delineation between stanzas. It’s just a byte stream of XML. No
> 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
> one byte at a time and wait for valid input before passing the message
> 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...
More information about the Standards