I have UDP network traffic arriving on my machine (OSC traffic from an iPad, to be exact) and I want two programs to be able to receive that traffic. The problem is that I can't bind to the same network port with two programs at once and I can't send to multiple ports with the iOS app I'm using. How can I solve this problem?
You can use the power of the command line for this. The following snippet uses socat
(probably needs to be installed beforehand) and tee
(should be preinstalled on any OS X or Linux).
socat -u UDP4-RECVFROM:8123,fork - | tee >(socat -u - UDP4-SENDTO:localhost:8223) | socat -u - UDP4-SENDTO:localhost:8323
Explanation: socat
listens for traffic on UDP port 8123, pipes it to tee
, which pipes it to two other instances of socat
forwarding it to ports 8223 and 8323 on localhost respectively. With your two programs you need to listen to those ports on localhost.