I don't think you're going to manage this with either netcat or socat. I have just done extensive tinkering with both, and socat looked the most promising.
I managed to set socat up to connect to the remote TCP port and listen on a local unix domain socket (in theory so the link could be kept up all the time) but as soon as the local process detatched from the unix socket (another socat linking the unix socket to stdin/out) it closed the TCP socat session.
The problem here is that each connection through netcat / socat makes a new TCP stream connection to the server, and it closes that TCP stream session when the local end disconnects.
I think you're probably going to have to write some custom proxy software for this that opens the TCP connection to the remote end and then listens locally on a socket / pipe / fifo or whatever and then just sends the data down the existing TCP pipe and returns the results.
Are you sure it is not the remote host that closes the connection? – user1686 – 2011-03-24T17:18:16.053
Yes. Doing netcat and then manually typing the command results in netcat staying alive indefinitely. – Chris – 2011-03-24T17:40:50.167
Why would it stay alive? it just print the echo parameters and then die? – M'vy – 2011-03-24T17:41:32.787
1I want it to stay alive so that it continues to receive the data coming from the remote server. – Chris – 2011-03-24T18:01:07.060
If you do it the way you wrote it, you just send to the remote server. If you want to receive something, you need to open a listening netcat on the local. – M'vy – 2011-03-24T18:15:53.083
2That's not true. "netcat <host> <port>" opens a bidirectional TCP socket. – Chris – 2011-03-24T18:41:39.723