0

I have some bots built with XMPP4r and I'm seeing a strange problem where they will appear offline after being online for a while. (no set amount of time)

I'll see them fine in my roster one night, and the next morning I'll wake up the next morning and find them appearing offline. I can send them a message and they respond fine, they just appear offline.

If I restart them, they will immediately show up in my roster again. This happens with multiple XMPP clients (iChat, Adium, Meebo) and multiple, separate bots, so I don't think it's a fluke.

Any recommendations on where I should start looking? I'm running my own Prosody server so I know it's not a reboot. Could it be a silent reconnect issue?

Scott
  • 1,164
  • 2
  • 14
  • 24
  • After some more research, I notice that I'm not replying to IQ pings. This might have something to do with it - checking. – Scott Jun 07 '11 at 00:48
  • In case this helps anyone, responding to IQ pings did not help, though it's something I should have been doing anyway. What did seem to help was creating a thread that changed my presence hourly - this feels kind of hacky and I'd like to know a better solution. – Scott Jun 15 '11 at 14:44
  • Well, in case it helps - I have a hacky solution. In my bot class, I have a timer that changes my presence status message every hour. (It appears that I have to change it do different text, I can't just try to resend my presence with the same message again) I don't love this approach, but my bots have been running for over a week with no problem. – Scott Jun 23 '11 at 15:52

1 Answers1

1

Suddenly our friendly jabber bot named Bender stopped working, I found that the main problem is that the server sends a ping like the following:

<iq from='capulet.lit' to='juliet@capulet.lit/balcony' id='s2c1' type='get'>
  <ping xmlns='urn:xmpp:ping'/>
</iq>

And the client is supposed to respond like this:

<iq from='juliet@capulet.lit/balcony' to='capulet.lit' id='s2c1' type='result'/>

More info at http://xmpp.org/extensions/xep-0199.html#s2c

This happened to me when trying to connect to a Mountain Lion Server messages server (perhaps other servers have the same requirement).

A friend found a simple way to solve this:

#!/usr/bin/env ruby
require 'rubygems'
require 'xmpp4r'
require 'xmpp4r/roster'
require 'xmpp4r/client'
require 'xmpp4r/muc'

Jabber::debug = true
client = Jabber::Client.new(Jabber::JID.new('user@macbook.local'))
client.connect
client.auth('password')
muc = Jabber::MUC::MUCClient.new(client)
muc.join(Jabber::JID::new('chatroom@conference.macbook.local' + client.jid.node))

# add the callback to respond to server ping
client.add_iq_callback do |iq_received|
  if iq_received.type == :get
    if iq_received.queryns.to_s != 'http://jabber.org/protocol/disco#info'
      iq = Jabber::Iq.new(:result, client.jid.node)
      iq.id = iq_received.id
      iq.from = iq_received.to
      iq.to = iq_received.from
      client.send(iq)
    end
  end
end

I hope this code helps some else.

Greetings Eduardo

Eduardo
  • 11
  • 1