This is only for http but I think you should take a look at Netcat. http://nc110.sourceforge.net/
For protocol aware redirection, there are various reverse proxies with that ability. TCPMUX was probably one of the firsts, but it requires explicit support by the client. Delegate[1], on the other hand, can identify the protocol and multiplex based on that, IINM.