[Twisted-Python] Closing Jabber connection

Carolina Ardohain carolinaardohain at gmail.com
Mon May 2 08:43:05 MDT 2005


I try to launch several jabber connections (BTW I use twisted 1.3).
When the login is successful there's no problem, but whe the password
is wrong I wanna to disconnect, I call connector.disconnect() but the
event client.BasicAuthenticator.AUTH_FAILED_EVENT keep calling again
and again. How I should close the connection so that event don't be
called anymore?

from twisted.protocols import jabber, xmlstream 
from twisted.protocols.jabber import client, jid
from twisted.internet import reactor, defer

class Connection:
    def __init__(self, who, myjid):
        self.jid = jid.JID(myjid)
        self.who = who

    def connect(self, passwd, port=5222):
        self.factory = client.basicClientFactory(self.jid, passwd)
        
        self.factory.addBootstrap(xmlstream.STREAM_AUTHD_EVENT,
self.onAuthSuccess)
        self.factory.addBootstrap(client.BasicAuthenticator.AUTH_FAILED_EVENT,
self.onAuthFailed)
        
        self.connector = reactor.connectTCP(self.jid.host, port, self.factory)
    
    def onAuthSuccess(self, stream):
        print "%s: Successful connection" % (self.who)
        self.stream = stream

    def onAuthFailed(self, stream):
        print "%s: Failed connection" % (self.who)
        self.connector.disconnect()

c1 = Connection('1', 'client1 at localhost/res1')
c2 = Connection('2', 'client2 at localhost/res1')
c1.connect('client1')
c2.connect('client22')

reactor.run()


The output is ('2' has wrong password)

1: Successful connection
2: Failed connection
2: Failed connection
2: Failed connection
2: Failed connection
....
2: Failed connection




More information about the Twisted-Python mailing list