best xmpp (google chat) lib in golang?

4,120 views
Skip to first unread message

Steven Degutis

unread,
Sep 5, 2012, 9:59:40 PM9/5/12
to golan...@googlegroups.com
I have half a mind to experiment with writing my own google-chat-based instant messenger in the next year, and Go seems like a great language to do this in. Does anyone recommend a particular library for interfacing with google's xmpp servers?

-Steven

Kyle Lemons

unread,
Sep 6, 2012, 3:37:02 PM9/6/12
to Steven Degutis, golan...@googlegroups.com
I have heard good things about libpurple for chat clients if you don't want to interact with the protocol.  Since XMPP is XML, though, and fairly straightforward, you could probably.get it done with the built-in xml support.

John Beisley

unread,
Sep 7, 2012, 2:30:19 AM9/7/12
to Steven Degutis, golan...@googlegroups.com

https://github.com/mattn/go-xmpp says it was forked from an original effort by rsc. Never tried it myself, though.

Jesse McNelis

unread,
Sep 7, 2012, 2:53:19 AM9/7/12
to Steven Degutis, golan...@googlegroups.com
Perhaps,
https://github.com/agl/xmpp



--
=====================
http://jessta.id.au

Russ Cox

unread,
Oct 9, 2012, 10:25:26 AM10/9/12
to chris.j...@gmail.com, golan...@googlegroups.com

Steven Degutis

unread,
Oct 9, 2012, 10:39:13 AM10/9/12
to golan...@googlegroups.com, chris.j...@gmail.com
Perfect! Thanks!

-Steven

Steven Degutis

unread,
Oct 9, 2012, 11:20:02 PM10/9/12
to golan...@googlegroups.com, chris.j...@gmail.com
Russ, I'm having a bit of trouble sending from this package. Every time I send to a user, I get an xmpp.Chat back that is identical to what I tried to send except with Type as "error". Following your example code in http://code.google.com/p/rsc/source/browse/google/acme/Chat/main.go I am creating a new xmpp.Chat with Remote equal to the receiving chat.Remote up to but not including the first "/" character, with Type as "chat" and Text as a string. Is this not correct?

Kyle Lemons

unread,
Oct 10, 2012, 3:34:19 PM10/10/12
to Steven Degutis, golan...@googlegroups.com, chris.j...@gmail.com
Can you print out the raw XML? An XMPP error should have some explanatory text saying what it is, though I seem to recall it not being easy to programatically extract.

--
 
 

Steven Degutis

unread,
Oct 10, 2012, 3:40:51 PM10/10/12
to golan...@googlegroups.com, Steven Degutis, chris.j...@gmail.com
I tried that very debugging technique but could not figure out where to print out the raw XML request in his xmpp library.

-Steven
Message has been deleted

Kyle Lemons

unread,
Oct 10, 2012, 4:00:11 PM10/10/12
to Steven Degutis, golan...@googlegroups.com, chris.j...@gmail.com
I'd inject a multiwriter / teereader in between the connection and the xml encoder/decoder, with the second stream going to stdout.

--
 
 

Steven Degutis

unread,
Oct 10, 2012, 4:21:21 PM10/10/12
to golan...@googlegroups.com, Steven Degutis, chris.j...@gmail.com
Oh I see now. When I send a response chat back to whoever sends me a chat (like an echo server), via client.Send(xmpp.Chat{Remote: incomingChat.Remote, Type: "chat", Text: "foobla"}) then I get this XML response back:

<message to="" from="igno...@real.email.com" type="error" xml:lang="en"><body>foobla</body><error code="400" type="modify"><jid-malformed xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Malformed JID '': domain is empty</text></error></message>

But as far as I can tell the sample code Russ posted previously does this same thing. I've also tried not deleting everything including and after the first slash from the incoming name, but I get basically the same response back, with definitely the same error:

<message to="" from="igno...@real.email.com/Steven’s MA48440E8" type="error" xml:lang="en"><body>foobla</body><error code="400" type="modify"><jid-malformed xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Malformed JID '': domain is empty</text></error></message>

I'm just confused because as far as I can tell I'm doing the same thing Russ's sample code is doing at http://code.google.com/p/rsc/source/browse/google/acme/Chat/main.go

-Steven
Message has been deleted

Steven Degutis

unread,
Oct 11, 2012, 6:24:19 AM10/11/12
to golan...@googlegroups.com, Steven Degutis, chris.j...@gmail.com
Ah, I see. Turns out I'm sending:

<message to='a.r...@email.com/Steven’s MB694B29E' from='' type='chat' xml:lang='en'><body>foobla</body></message>

This seems to indicate that my Client object actually has an empty jid field, which appears to be a bug in Russ's xmpp library, I'm guessing somewhere around http://code.google.com/p/rsc/source/browse/xmpp/xmpp.go#213

I'll dig into it further, although I'm pretty confused by this code and not a very smart programmer so I'm not sure how much progress I can make. Russ if you're reading this, do you have any tips as to what could be causing it to get a wrong jid? I clearly see that in my response I'm getting this back:

<iq id="x" type="result"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>a.r...@email.com/23F41190</jid></bind></iq>

And when I print out the value of the iq object right after decoding it, sticking the printing code at line 214, I get this:

xmpp.clientIQ{XMLName:xml.Name{Space:"jabber:client", Local:"iq"}, From:"", Id:"", To:"", Type:"", Error:xmpp.clientError{XMLName:xml.Name{Space:"", Local:""}, Code:"", Type:"", Any:xml.Name{Space:"", Local:""}, Text:""}, Bind:xmpp.bindBind{XMLName:xml.Name{Space:"urn:ietf:params:xml:ns:xmpp-bind", Local:"bind"}, Resource:"", Jid:""}, Query:xmpp.clientQuery{Item:[]xmpp.rosterItem(nil)}}

And I believe it's using the above line of XML because on line 207 right before decoding the XML into the iq object, I'm printing "Starting to decode IQ!" and seeing it printed right before the above <iq> element.

-Steven


On Wednesday, October 10, 2012 4:12:42 PM UTC-5, PeteT wrote:
I'm just confused because as far as I can tell I'm doing the same thing Russ's sample code is doing at http://code.google.com/p/rsc/source/browse/google/acme/Chat/main.go

To help find the problem, I recommend logging what you are writing to the server in addition to what you are reading.

Kyle Lemons

unread,
Oct 11, 2012, 5:32:18 PM10/11/12
to Steven Degutis, golan...@googlegroups.com, chris.j...@gmail.com
On Thu, Oct 11, 2012 at 3:24 AM, Steven Degutis <sdeg...@8thlight.com> wrote:
Ah, I see. Turns out I'm sending:

<message to='a.r...@email.com/Steven’s MB694B29E' from='' type='chat' xml:lang='en'><body>foobla</body></message>

I can't tell if this is what you mean, but to me the 's looks like it's what's killing that line.
 
--
 
 

Russ Cox

unread,
Oct 16, 2012, 2:05:25 PM10/16/12
to Kyle Lemons, Steven Degutis, golan...@googlegroups.com, chris.j...@gmail.com
Sorry, I have been without time to read golang-nuts for a week or so.
It seems entirely possible that I screwed up the jid when I updated
the code to work with Go 1 [sic]. My suggestion would be to diff my
code against mattn's code on github. I prefer the API of my package
but I haven't used it recently. Mattn's code may be semantically
better as far as XMPP protocol details.

Russ
Reply all
Reply to author
Forward
0 new messages