TCP Portforwarding

Dave Brueck dave at pythonapocrypha.com
Sat May 17 16:16:48 EDT 2003


On Sat, 17 May 2003, Thomas Guettler wrote:

> I want to forward a tcp port to a remote machine:
>
>  localhost:2000 --> remote:80
>
> All requests to localhost:2000 should be forwarded to remote:80. I
> thought that this would be easy, but it is more difficult as I
> thought.
>
> I think this should be possible with less than 100 lines. Or am I
> wrong?

That's seems about right for something simple, although it may grow beyond
that with error handling code. Is this port-forwarder protocol agnostic or
do you know something about the nature of the traffic?

> socket.recv() needs a buffer length. Which length is advisable?

Doesn't matter too much for many applications - use 64k.

> What are the pros and cons of select vs. poll?

Poll is more efficient and can handle a larger number of active
connections. If you're doing less than about 1000 then it won't matter too
much which you use.

-Dave





More information about the Python-list mailing list