[Twisted-Python] Sending Data via a client
johann.borck at densedata.com
Fri Oct 12 17:39:27 EDT 2007
Simon Pickles wrote:
> Twisted is event driven.
> So how do I send Data through a client? All the example demonstrate is
> how to receive events.
Here is just one of the examples available, it's actually googles first
hit for "twisted client example":
The function "finger" shows what is needed to start up a client.
> I suppose what I am asking is how do I refer to a client protocol from
> another class?
> My variable:
> loop = = gatewayClient().start()
> opens a reconnectingClientFactory, which opens a client protocol. How
> do i make that client protocol global enough to use from anywhere in
> my app?
you "import MyFactory from mymodule" and use it as shown in example. You
can do that anywhere in your app.
> The ironic thing is, its easy with sockets :)
I'd say the ironic thing is that sockets are so often used in a
different way, imposing lots of unnecessary problems (apart from the
fact that this is a rtfm question) :). What twisted gives you for free
is a rock-stable way to do all networking asynchronous, which is no
trivial task to achieve using sockets (i.e. writing a twisted equivalent
from scratch). When you get used to it, it won't be harder to do simple
things, and way easier to do complex things. It's certainly worth the
More information about the Twisted-Python