I have the following TCP server:
socat TCP-LISTEN:10000,fork,reuseaddr SYSTEM:'read -r msg && sleep 3 && echo "OK"'
When I execute (interactive mode):
socat - TCP:localhost:10000
> some text here [ENTER]
It will return "OK" after 3 seconds (as expected)
However, I need to do it non-interactive:
response=$(echo "some text" | socat - TCP:localhost:10000)
But it returns immediately without response and the server reports after 3 seconds echo: I/O error
(as the client is no longer connected).
If I remove "sleep 3" from the server, it works fine, but I need the "sleep" to work (as I'm actually executing a command that may sleep until it gets some response from another server).
How can it be fixed?
- Using Ubuntu 22.04
- It doesn't need to use
socat
as client - Ultimately the server and the client will be on different servers.