0

Say I have a netcat server running like so:

nc -l 4444 | while read line; do
  # how can I write back to the socket?
done;

the only thing I have found so far in my search is to use the -c option to respond:

nc -l 4444 -c 'echo "this is the response"'

is there another way to write to the socket connection?

  • 2
    Netcat reads from stdin and sends these data to the peer. But for me this looks like an [XY problem](https://en.wikipedia.org/wiki/XY_problem), i.e. there is some unknown problem X where you've decided that the proper way to solve it is Y which involves using netcat even though it might not be the right tool to solve X. Given that X is the ultimate problem you have it might be more useful to provide this problem instead focus too much on your idea Y only. – Steffen Ullrich Jun 05 '19 at 02:55
  • here is the actual problem here - https://unix.stackexchange.com/questions/522944/how-can-a-client-talk-to-another-client-using-unix-domain-sockets –  Jun 05 '19 at 03:40
  • This "actual problem" is also mostly an XY problem where the OP is explicitly trying to solve a not fully known task with shell scripting and netcat even though it does not seem to be the right tool to solve the problem. – Steffen Ullrich Jun 05 '19 at 03:54
  • 1
    Since netcat reads from stdin, anything you type in the server console will be sent to the client. Perhaps you can be more specific on what you need. – President James K. Polk Jun 05 '19 at 16:13
  • netcat is apparently the wrong tool for the problem, but by the same token I guess so is bash the wrong tool for the problem. But I swear it can be done by bash, and I am just curious how it can be done. I basically need to store socket connections and write to them later (and contingently). –  Jun 05 '19 at 18:08

0 Answers0