Hello,

Socat is not able to do this, and there is currently no plan to implement this feature.

However, due to the repeated requests, a script socat-mux.sh has been written and released with Socat 1.8.0.0 that is able to provide many-to-one, one-to-all communications. Internally it utilizes two Socat (parent) processes that use UDP broadcast on loopback interface for data multiplication. Please note that this has a security risk because local users are able to join the communications.

The script provided with 1.8.0.0 requires this actual Socat version; in the next bug fix release a backported version will be included for older Socat versions, find it attached to this message.

You should be able to realize your use case with the following command:

    socat-mux.sh UNIX-LISTEN:sock,unlink-early=1,fork \
        TCP-CONNECT:1.2.3.4:1234

Hope this helps!
- Gerhard


Am 01.05.24 um 07:34 schrieb Paul Wise:
Package: socat
Severity: wishlist
X-Debbugs-Cc: so...@dest-unreach.org
Forwarded: so...@dest-unreach.org

socat does not appear to have a way to send data to multiple clients of
a listening socket, which would be useful to proxy data from overloaded
servers to multiple local clients.

For example:

    socat TCP-CONNECT:1.2.3.4:1234 UNIX-LISTEN:sock,unlink-early=1 &
    socat UNIX-CONNECT:out STDOUT &
    socat UNIX-CONNECT:out STDOUT &

The second client is not allowed to connect to the socket:

    2024/05/01 13:12:32 socat[957352] E connect(, AF=1 "out", 5): Connection 
refused

This can be achieved, by using this nmap ncat command:

    ncat --listen --unixsock out --keep-open --send-only

This appears to work by reading some data, then writing it
to all the client sockets, then repeating the process.

Unfortunately ncat breaks when one of the clients terminates,
so ncat currently does not appear to be useful for this yet.

    Ncat: Program bug: fd (4) not on list. QUITTING.

PS: some places on the web where people are looking for this feature,
for both local Unix domain stream sockets and local TCP ports:

https://serverfault.com/questions/747980/simpliest-unix-non-blocking-broadcast-socket
https://unix.stackexchange.com/questions/195880/socat-duplicate-stdin-to-each-connected-client
https://stackoverflow.com/questions/17480967/using-socat-to-multiplex-incoming-tcp-connection
https://gist.github.com/mathieue/3505472

Attachment: socat-mux.sh
Description: application/shellscript

Reply via email to