Contents
When to exit netcat service after receiving input?
The default netcat listener should exit upon receiving input (in this case your echo pipes it to netcat which forwards it to the listener). If you want the listening Netcat service to stay listening after it receives input:
How to close the connection gracefully with netcat?
Works as Ansible command. Actually, the best way to close gracefully the connection is to send the Content-Length header like following. Client (like curl will close the connection after receiving the data. This waits 10 sec before closing the connection. This keeps the input open for some time to delay netcat ending.
How is a netcat command supposed to work?
Your command should work. It is very similar to some of the examples in the netcat manpage. This is exactly how netcat is supposed to operate: once it has reached EOF on stdin, it (one-way) closes the connection /to/ the server and then waits for data coming from the server.
Why does NC never receive response to my _ command string?
The problem is that nc will close the connection immediately after stdin is closed, which is very quick for a simple my_command string, and thus never gets the chance to receive a response. If you pipe a very large file you will see that it might get a response before it’s done sending the file.
How to get the exit status of a pipe in Bash?
There’s an array that gives you the exit status of each command in a pipe. This solution works without using bash specific features or temporary files. Bonus: in the end the exit status is actually an exit status and not some string in a file. you want the exit status from someprog and the output from filter.
How to pipe a large file in netcat?
If you pipe a very large file you will see that it might get a response before it’s done sending the file. Enter cat with – as second argument: it makes cat listen on stdin for more content to pipe through after it has sent the contents of the first argument.
What happens after echo writes test in SOCAT?
So above, after echo writes test , it exits, which closes the pipe. socat sees EOF on its – channel (stdin), then shuts the writing direction of the TCP socket and waits for the remote service to shutdown as well or for 10 seconds of inactivity whichever comes first.