views:

237

answers:

1

I am writing a chatbot using Twisted and wokkel and everything seems to be working except that bot periodically logs off. To temporarily fix that I set presence to available on every connection initialized. Does anyone know how to prevent going offline? (I assume if i keep sending available presence every minute or so bot wont go offline but that just seems too wasteful.) Suggestions anyone? Here is the presence code:

class BotPresenceClientProtocol(PresenceClientProtocol):

    def connectionInitialized(self):
        PresenceClientProtocol.connectionInitialized(self)
        self.available(statuses={None: 'Here'})

    def subscribeReceived(self, entity):
        self.subscribed(entity)
        self.available(statuses={None: 'Here'})

    def unsubscribeReceived(self, entity):
        self.unsubscribed(entity)

Thanks in advance.

+2  A: 

If you're using XMPP, as I assume is the case given your mention of wokkel, then, per RFC 3921, the applicable standard, you do need periodic exchanges of presence information (indeed, that's a substantial overhead of XMPP, and solutions to it are being researched, but that's the state of the art as of now). Essentially, given the high likelihood that total silence from a client may be due to that client just going away, periodic "reassurance" of the kind "I'm still here" appears to be a must (I'm not sure what direction those research efforts are taking to ameliorate this situation -- maybe the client could commit to "being there for at least the next 15 minutes", but given that most clients are about a fickle human user who can't be stopped from changing their mind at any time and going away, I'm not sure that would be solid enough to be useful).

Alex Martelli
hmm interesting. i was hoping there would be some kind of a ping mechanism e.g. server tries to ask client for their state just before it assumes client is offline (like tom mentioned in a comment above for irc networks). oh well. thank you.
dmitriy k.
@dmitry, I believe you can implement that conformantly as an XMPP extension, but it's not specified as part of the standard and I believe (though I might be wrong!) that wokkel has no such extension (if it did you could surely find it spelled out in the wokkel docs).
Alex Martelli
Many XMPP clients and servers will periodically send a single space if they haven't sent or received traffic recently. This is enough to wake up the TCP stream, and eventually cause timeouts that will mark that client as unavailable.
Joe Hildebrand