我有一个 MyJabber 类,它初始化一个基本的 jabber 帐户,将传入的消息打印到标准输出 + 将它们放入队列中。
将客户端添加到反应器的代码是这样的:
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)
它是这样调用的:
jabber = MyJabber(options, to_irc)
jabber.addReactor()
reactor.run()
当我启动应用程序时,我看到了 addReactor 的“打印”,但之后就什么也没有了。我通过“tcpdump”看到有东西试图连接到“jabber.org”,但与 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)