Twisted - extending portforward (simple example)

Paul Moore paul.moore at atosorigin.com
Fri Jun 27 12:42:20 CEST 2003


I hit a problem yesterday with my mail connection. In a desparate
attempt to understand what was going on, I wanted to log the
connection traffic. After a bit of searching, I found a post on c.l.p
from Andrew Bennetts explaining how to run a port forwarder in 2 lines
using Twisted.

    $ mktap portforward -p 8000 -h remote -d 20
    $ twistd -f portforward.tap

This looked brilliant - all I needed to do was add logging. A quick
look (I was *very* short of time, so I couldn't spend long) showed me
no obvious way of adding a hook (at least, not one which wouldn't turn
the above 2-liner into something more complex, that I didn't have time
to work out...) So I gave in, and just added a print statement in the
twisted code.

This gave me the results I wanted, but left me wondering (and not
getting far in finding out!) how I *should* have done this.

Ideally, I was expecting to be able to write a small .py file,
importing and minimally overriding portforward.py, and then be able to
do the mktap/twistd thing. But I couldn't see how.

Can anyone give me a simple example of how I should have done this?
The logging portforwarder example seems like a nice simple starting
point, from which I can go on and learn how to do clever stuff :-)

Thanks,
Paul.

PS Many thanks to the twisted crew - even if I didn't do things the
"right" way, I got my problem diagnosed in no time at all, when I'd
previously struggled with it for days!




More information about the Python-list mailing list