Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > 7b973fb3c8298f606d9b435aff551ab6 > files > 2996

python2-twisted-19.2.1-1.1.mga7.armv7hl.rpm


:LastChangedDate: $LastChangedDate$
:LastChangedRevision: $LastChangedRevision$
:LastChangedBy: $LastChangedBy$

The Evolution of Finger: a Twisted finger client
================================================






Introduction
------------



This is the ninth part of the Twisted tutorial :doc:`Twisted from Scratch, or The Evolution of Finger <index>` .




In this part, we develop a client for the finger server: a proxy finger
server which forwards requests to another finger server.





Finger Proxy
------------



Writing new clients with Twisted is much like writing new servers.
We implement the protocol, which just gathers up all the data, and
give it to the factory. The factory keeps a deferred which is triggered
if the connection either fails or succeeds. When we use the client,
we first make sure the deferred will never fail, by producing a message
in that case. Implementing a wrapper around client which just returns
the deferred is a common pattern.  While less flexible than
using the factory directly, it's also more convenient.



Additionally, because this code now programmatically receives its host and
port, it's a bit less convenient to use clientFromString. Instead, we move to
using the specific endpoint we want. In this case, because we're connecting as
a client over IPv4 using TCP, we want the ``TCP4ClientEndpoint``.






:download:`fingerproxy.tac <listings/finger/fingerproxy.tac>`

.. literalinclude:: listings/finger/fingerproxy.tac