I was able to achieve this by redirecting output to a fifo, and using the fifo as the input for nc:
#/bin/sh -e
# create a fifo
unlink /tmp/f
mkfifo /tmp/f
# connect to the server in the background
nc localhost 4444 < /tmp/f &
# redirect stdout to the fifo
exec > /tmp/f
# an example that writes to stdout
while [ 1 ];true; do
sleep 1
echo "hello world"
done
Note this is only transmitting stdout to the socket; you could add exec 2> /tmp/f to include stderr. I didn't succeed at getting stdin wired up but it should be possible.
(An earlier version of this script swapped nc with exec; this worked on Zsh, but not BusyBox's shell, ash.)