Explanation
It's about stdin of socat
.
For a command run in the background with &
, there are basically two possibilities:
If job control is disabled in the shell (this is the default for scripts), stdin of the command shall be redirected (before any explicit redirections are performed) to
/dev/null
or an equivalent file.If job control is enabled in the shell (this is the default in interactive usage), stdin of the command is what you expect, so it may be the terminal. If it's the terminal, the command in the background cannot steal input from it; if it tries then it will get SIGTTIN. Still you can bring the command to the foreground with
fg
and then it can read from the terminal.
nohup
on its own redirects standard streams away from the terminal, so even in the latter case your socat
in the background or any of its children/threads/whatever will get the EOF condition (or some error) immediately when it tries to read from its stdin.
You should be able to pass data quickly with like echo message | nc localhost 8080
, socat
handling this particular connection should get the message before terminating because of EOF on its stdin.
Solution
If you don't want connections to terminate because of EOF on the stdin of socat
, tell the tool not to read from this address. From man 1 socat
:
-u
Uses unidirectional mode. The first address is only used for reading, and the second address is only used for writing (example).
-U
Uses unidirectional mode in reverse direction. The first address is only used for writing, and the second address is only used for reading.
In your case -
(meaning STDIO
) is the second address, so you need -u
:
nohup socat -u -x -d -d -d tcp-l:8080,bind=0.0.0.0,fork,reuseaddr - 2>stderr.log >stdout.log &