Martin Broadhurst

TCP Proxy

This is about as simple as a TCP proxy can be. It accepts one client connection at a time, but you can easily allow it to accept more by using the methods demonstrated in the server examples. You can use it as a starting point to write a more sophisticated proxy, that, for example, writes the transfers to a file, or modifies the data being exchanged.

The thing to remember when writing a proxy is that you need to call select before every call to read or recv, unless you know how many more bytes there are. This is because if there are no more bytes left, read and recv will block, which will cause the proxy to freeze. read and recv only return 0 when the peer has disconnected.

Copyright (C) 2010 Martin Broadhurst