我有一个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)
解决方法:
这似乎不是关于如何“启动扭曲电抗器”的真正问题.相反,似乎更多有关如何使用Twisted Words的XMPP支持来发送和响应XMPP消息.
您可以在Twisted Words示例目录中找到几个执行此操作的示例:
http://twistedmatrix.com/documents/current/words/examples/
尝试使用xmpp_client.py和jabber_client.py.