How to start a twisted reactor?

I have a MyJabber class that runs the main jabber account, which prints incoming messages to stdout + and queues them.

The code that adds the client to the reactor is:

def addReactor(self):
    print 'inside  AddReactor'
    factory = client.basicClientFactory(self.jid, self.option['jabber']['password'])
    print "factory initialized"
    factory.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self.authd)
    print 'factory bootsraped'
    reactor.connectTCP(self.option['jabber']['server'], 5222, factory)

it calls like this:

jabber = MyJabber(options, to_irc)
jabber.addReactor()
reactor.run()

When I launch the application, I see addReactor "print", but after that nothing more. I see something trying to connect to jabber.org through tcpdump, but nothing has to do with authd def:

def authd(self, xmlstream):
    global thexmlstream
    thexmlstream = xmlstream
    # need to send presence so clients know we're
    # actually online.
    print 'Initializing...'
    presence = domish.Element(('jabber:client', 'presence'))
    presence.addElement('status').addContent('Online')

    xmlstream.send(presence)
    # add a callback for the messages
    print 'Add gotMessaged callback'
    xmlstream.addObserver('/message', gotMessage)
    print 'Add * callback'
    xmlstream.addObserver('/*', gotSomething)
+3
source share
2 answers

Actually, this is not a question of how to “start a twisted reactor”. Most likely, it seems like using XMPP Twisted Words support to send and reply to XMPP messages.

, Twisted Words:

http://twistedmatrix.com/documents/current/words/examples/

xmpp_client.py jabber_client.py.

+4

, 2 .

1) , JID - name@domain.tld/extra

2) self. gotMessage/gotSomething

addReactor factory main() :

jabber = MyJabber(options, to_irc)
factory = jabber.addReactor()
reactor.connectTCP(options['jabber']['server'], 5222, factory)
reactor.run()
0

Source: https://habr.com/ru/post/1732839/


All Articles