[Twisted-Python] XMPP server connection question

Ralph Meijer twisted at ralphm.ik.nu
Fri Dec 5 06:23:42 EST 2008

On 2008-12-05 11:42, Phil Mayers wrote:
> Christopher Zorn wrote:
> Yeah, the t.w.p.j.xmlstream.XmlStreamFactory inherits from 
> ReconnectingClientFactory, which is IMHO wrong.
> See also:
> http://twistedmatrix.com/trac/ticket/3492

Wrong? It was just a design choice for this particular factory, made 
more than five years ago. Since then, the code has been refactored in 
such a way that it is pretty straightforward to have a non-reconnecting 
XMPP client:

from twisted.words.xish.xmlstream import BootstrapMixin
from twisted.internet import protocol

class NonReconnectingXmlStreamFactory(BootstrapMixin,
     XmlStream factory that connects at most once.

     @ivar authenticator: The authenticator to be associated with the
                          XmlStream once a connection has been

     def __init__(self, authenticator):
         self.authenticator = authenticator

     def buildProtocol(self, addr):
         Create an instance of XmlStream and associate the authenticator.
         xs = self.protocol(authenticator)
         return xs

You can then also override protocol.ClientFactory's
clientConnectionFailed and clientConnectionLost as desirable. You should
probably add bootstrap handlers for STREAM_AUTHD_EVENT,

I have a similar special client factory in Wokkel that fires a deferred
as soon as a connection was made and the stream is authenticated. See


More information about the Twisted-Python mailing list