With Bash process-substitution
Multiplexing from the shell can in general be achieved with coreutils tee
and Bash process-substitution. So for example to have the socat-stream multiplexed to multiple pipelines do something like this:
socat -u tcp-l:42000,fork,reuseaddr system:'bash -c \"tee >(sed s/foo/bar/ > a) >(cat > b) > /dev/null\"'
Now if you send foobar
to the server:
socat - tcp:localhost:42000 <<<fobar
Files a
and b
will contain:
a
barbar
b
foobar
With named pipes
If the pipelines are complicated and/or you want to avoid using Bash, you can use named pipes to improve readability and portability:
mkfifo x y
Create the reader processes:
sed s/foo/bar/ x > a &
cat y > b &
Start the server:
socat -u tcp-l:42000,fork,reuseaddr system:'tee x y > /dev/null'
Again, send foobar
to the server:
echo foobar | socat - tcp:localhost:42000
And the result is the same as in the above.