[Twisted-Python] Factory question

Drew Smathers drew.smathers at gmail.com
Wed Feb 27 11:12:53 EST 2008

On Wed, Feb 27, 2008 at 3:32 AM, Gabriel Rossetti
<mailing_lists at evotex.ch> wrote:
> Hello everyone,
>  I have a small question, I have a service which needs to sometimes send
>  data (without having received any prior to sending) and sometimes
>  receive data, which is better :
>  1) create a factory that inherits from ServerFactory and ClientFactory,
>  thus it can listen and send data
>  2) create a factory that inherits from ServerFactory only and uses a
>  single-use client (ClientCreator, as shown in the writing clients howto)
>  when it needs to send data

I'm not sure of there's a single right way to do it, but I wouldn't
bother inheriting from both ClientFactory and ServerFactory.  I think
you're on the write track with 2, though.

In most use cases you shouldn't have to create custom factories.  Just
write the protocol to support bidirectional comm and to create the

f = Factory()
f.protocol = YourBidirectionalProtocol

Regarding the client, how you implement it depends on whether or not
the server is establishing the connection vs. reusing the existing
connection.  If you're establishing the connection (like in a cluster
app with known peers), just use ClientCreator.  If you're reusing the
existing connection, then you might not have to anything, unless you
have some state to set up which could be done by overriding
connectionMade on your Protocol.

Finally, take everything I've stated above with a grain of salt.

\\\\/ // //\/\\\\\\\
\\\/  \\// /\ \/\\\\
\\/ /\/ / /\/ /\ \\\
\/ / /\/ /\  /\\\ \\
/ /\\\  /\\\ \\\\\/\

More information about the Twisted-Python mailing list