17

I'd like to redirect an applications input and output to a unix socket and connect to that socket from another session. What I'm doing so far is the following:

On the "server" side:

socat EXEC:"command" UNIX-LISTEN:/tmp/comm

And on the "client" side:

socat UNIX-CONNECT:/tmp/comm -

It works pretty good, but as soon as the client-side socat terminates, the server terminates, too. But I'd like it to keep running and reconnect later... How do I accomplish that?

bot47
  • 1,238
  • 4
  • 14
  • 23

1 Answers1

17

You must use fork option, which handle a connection in a child process, make the parent process attempt to handle more connections.

In first terminal:

$ socat - UNIX-LISTEN:/tmp/comm,fork

In second terminal:

$ socat UNIX-CONNECT:/tmp/comm -

Press Ctrl+C in second terminal, switch to the first terminal and see your server is still running.

cuonglm
  • 150,973
  • 38
  • 327
  • 406