3

I want to create an echo server without specifying any of my commands inside strings. I want all commands to be connected by pipes.

This doesn't appear possible because the response gets returned before the request can be passed to the response generating logic. It seems I could use ncat but I also would prefer to avoid that.

I thought it might be possible with a fifo queue but I'm having trouble getting this to work.

The "What I'm trying to do" part

Attempting to justify these restrictions is challenging with my limited verbal skills. But my ultimate goal is to maintain a master script of all my application logic with the convenience of xinetd (but without daemons). Such a master script might have dozens of lines like these:

nc -l 8080 | get_person_name.sh | create_insert_statement.sh | sqlplus
nc -l 8081 | get_person_id.sh | create_select_statement.sh | sqlplus

The 2nd one won't work because it won't be able to return the output to the client. So I'm reducing the problem to implementing an echo server with netcat. I don't want to use strings because all those commands will be dynamic and I just don't want to deal with that extra level of indirection (for a start, my text editor will have far less useful syntax highlighting). I'd be open to a here document solution though.

  • After further experience, my recommendation is not to use netcat for this purpose but your own homemade port listener (I call mine httpcat.groovy and it works excellently in my use cases so far). – Sridhar Sarnobat Nov 29 '16 at 22:24
  • There's a program called tcpserver that might make this easier – Sridhar Sarnobat Jan 28 '17 at 23:27
6

This does what I want:

Server:

mkfifo fifo
cat fifo  | nc -k -l 4458 -v | cat  > fifo

Client:

echo "45" | nc localhost 4458 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.