1

I need to invoke a program x on server foo from client bar. Program x takes some time to load, then reads input from stdin and transmits output to stdout before terminating. I've been trying to use socat to accomplish this.

On server foo I setup the following:

socat -lmlocal2 TCP-LISTEN:4444,fork,reuseaddr,linger=6 SYSTEM:x

And to invoke the command I run this on client bar:

echo "someinput" | socat - TCP:foo:4444

When I run the client with -v I can see socat is transmitting the data to foo, and if I run top on foo I can see it invoking x (which takes awhile to start up), but the client on bar doesn't wait around for x to finish, and socat on server foo reports an I/O error.

If I change the SYSTEM command on foo to "SYSTEM:sleep 5; cat > /tmp/test ; echo 'done'", it does correctly read however much input I send it and puts it into /tmp/test. The input is all transmitted over the network and fed to x, it's just the output of x that is lost.

How do I get the socat client to stay open until x finishes writing to stdout and closes it? I tried adding linger=6 to the server but that hasn't helped.

koehn
  • 291
  • 2
  • 10

1 Answers1

0

OK, I think I have it: put -t 10 on both client and server, and they'll both wait 10 seconds after EOF from the client before closing both sockets.

Protip: use lots of -d to get a view into what socat is doing behind the scenes, and create a simple local test case you can easily reproduce.

koehn
  • 291
  • 2
  • 10