From http://ademar.name/blog/2010/06/a-minimal-tcpip-proxy-implemen.html