如何正确启动扭曲反应堆?
我有一个 MyJabber 类,它初始化一个打印的基本 jabber 帐户 将传入的消息发送到 stdout + 将它们放入队列中。
将客户端添加到反应器的代码是这样的:
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)
i have a class MyJabber which init a basic jabber account that print
the incoming messages to stdout + put them into a queue.
The code that add the client to the reactor is this:
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's called in this way:
jabber = MyJabber(options, to_irc)
jabber.addReactor()
reactor.run()
When i launch the app i see the 'print' of addReactor but after that nothing anymore.
i see via 'tcpdump' that something is trying to connect to 'jabber.org' but nothing related to the 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎并不是一个关于如何“初始化扭曲反应堆”的问题。相反,它似乎更多地是关于如何使用 Twisted Words 的 XMPP 支持来发送和响应 XMPP 消息。
您可以在 Twisted Words 示例目录中找到几个执行此操作的示例:
http://twistedmatrix .com/documents/current/words/examples/
尝试
xmpp_client.py
和jabber_client.py
。This doesn't seem to really be a question about how to "init twisted reactor". Rather, it seems to be more about how to use Twisted Words' XMPP support to send and respond to XMPP messages.
You can find a couple examples which do this in the Twisted Words examples directory:
http://twistedmatrix.com/documents/current/words/examples/
Try
xmpp_client.py
andjabber_client.py
.已修复,有 2 个错误。
1) 我不小心忘记了 JID 是 [email protected]/extra
2 )忘记将
self.
添加到gotMessage/gotSomething
我还让 addReactor 返回工厂并在 main() 中写道:
Fixed, there were 2 errors.
1) I accidentally forgot that a JID is [email protected]/extra
2) Forgot to add
self.
togotMessage/gotSomething
I've also made addReactor return the factory and in the main() wrote: