Daniel Brockman
Daniel Brockman

Reputation: 19270

Bridging standard input/output over a TCP socket

I want to write a script that does the following:

  1. Start listening on a random available localhost TCP port.
  2. Start a certain external program passing the port number as an argument.
  3. Accept a single connection to the server socket.
  4. Send the script’s standard input into the socket, and the socket’s output to standard output.
  5. Exit when the external program exits.

The ideal solution would be a shell script invoking some reasonably standard tools, so if anybody can come up with a way to do that, well, that would be the perfect answer. If that proves intractable, a Ruby implementation would be convenient for me. Failing that, I’ll take any workable implementation.

P.S. I’m pretty new here, so please let me know if this question is too general or if it doesn’t belong for some other reason (maybe "please implement X for me" is frowned upon?).

Upvotes: 1

Views: 1476

Answers (1)

wildplasser
wildplasser

Reputation: 44220

Have you tried netcat ? Both listener and client can be done with nc.

Upvotes: 1

Related Questions