Simple continuous XMPP client in python

I am using python-xmpp to send jabber messages. Everything works fine, except that every time I want to send messages (every 15 minutes), I need to connect to the jabber server, and meanwhile the sending client is offline and cannot receive messages.

So, I want to write a really simple, indefinitely working xmpp client that is online all the time and can send (and receive) messages as needed.

My trivial (non-working) approach:

import time
import xmpp

class Jabber(object):
    def __init__(self):
        server = 'example.com'
        username = 'bot'
        passwd = 'password'
        self.client = xmpp.Client(server)
        self.client.connect(server=(server, 5222))
        self.client.auth(username, passwd, 'bot')
        self.client.sendInitPresence()
        self.sleep()

    def sleep(self):
        self.awake = False
        delay = 1
        while not self.awake:
            time.sleep(delay)

    def wake(self):
        self.awake = True

    def auth(self, jid):
        self.client.getRoster().Authorize(jid)
        self.sleep()

    def send(self, jid, msg):
        message = xmpp.Message(jid, msg)
        message.setAttr('type', 'chat')
        self.client.send(message)
        self.sleep()

if __name__ == '__main__':
    j = Jabber()
    time.sleep(3)
    j.wake()
    j.send('receiver@example.org', 'hello world')
    time.sleep(30)

The problem here is that I cannot wake her. My best guess is that I need some kind of concurrency. This is true, and if so, then how am I best to do this?

EDIT: , concurrency, wokkel. , .

+1
2

xmpppy ( python-xmpp), , : xtalk.py

, , jabber-, , .

. ( concurrency) , .

+2

Process(timeout) - , .

0

All Articles