如何正确启动扭曲反应堆?

发布于 2024-08-21 18:23:13 字数 1238 浏览 6 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

楠木可依 2024-08-28 18:23:13

这似乎并不是一个关于如何“初始化扭曲反应堆”的问题。相反,它似乎更多地是关于如何使用 Twisted Words 的 XMPP 支持来发送和响应 XMPP 消息。

您可以在 Twisted Words 示例目录中找到几个执行此操作的示例:

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

尝试 xmpp_client.pyjabber_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 and jabber_client.py.

疏忽 2024-08-28 18:23:13

已修复,有 2 个错误。

1) 我不小心忘记了 JID 是 [email protected]/extra

2 )忘记将 self. 添加到 gotMessage/gotSomething

我还让 addReactor 返回工厂并在 main() 中写道:

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

Fixed, there were 2 errors.

1) I accidentally forgot that a JID is [email protected]/extra

2) Forgot to add self. to gotMessage/gotSomething

I've also made addReactor return the factory and in the main() wrote:

jabber = MyJabber(options, to_irc)
factory = jabber.addReactor()
reactor.connectTCP(options['jabber']['server'], 5222, factory)
reactor.run()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文