#1070163 socat: support duplicating data to multiple clients of listening socket?

Package:
socat
Source:
socat
Description:
multipurpose relay for bidirectional data transfer
Submitter:
Paul Wise
Date:
2024-05-03 03:48:03 UTC
Severity:
normal
#1070163#5
Date:
2024-05-01 05:34:23 UTC
From:
To:
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

#1070163#10
Date:
2024-05-01 09:48:05 UTC
From:
To:
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:

#1070163#15
Date:
2024-05-01 09:48:05 UTC
From:
To:
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:

#1070163#20
Date:
2024-05-03 03:43:23 UTC
From:
To:
Thanks for the info!