views:

271

answers:

2

hi,

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)
+3  A: 

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.

Jean-Paul Calderone
Note Side:if i change the class definition, and i use the code as single app, it works fine. no problem with the reactor code.as i undestood the reactor component can be activated also outside the class definition because is a component shared by all protocol. but it hangs.So the point of the question is reactor related :) the xmpp code works fine :)
giskard
There's no fundamental difference between "outside the class definition" or (the implied) "inside the class definition". If the version of your code which takes one approach works while the version which takes a different approach doesn't, then you've introduced some bug when converting from one to the other. There's no way to know what bug just by reading the code you've posted here, though.
Jean-Paul Calderone
A: 

fixed there were 2 errors.

1) i accidentaly forgot that a JID si [email protected]/extra 2) forgot to add self. to gotMessage/gotSomething

i've also make 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()
giskard