如何在多个程序中接收相同的 udp-stream?多个、程序、如何在、stream

2023-09-07 13:30:30 作者:无处话凄凉

我有一个封闭的第三方系统,它发送一个单播 UDP 流 (MPEG-TS),我想在同一台计算机上的两个不同程序中访问它.我无法更改源上的任何内容,甚至 IP 或端口.

I have a closed third party system that sends a unicast UDP stream (MPEG-TS) that I'd like to access in two different programs on the same computer. I can not change anything on the source, not even IP or Port.

除了编写我自己的小程序来捕获流然后创建新流并重新发送两者之外,还有其他选择吗?

Is there any other option than to write my own little program that captures the stream and then creates to new streams and resends both?

似乎两个目标程序中只有一个处理多播,所以我需要两个单播流.

It seems that only one of the two destination programs handles multicast, so I need two unicast streams.

推荐答案

你应该可以使用 socat 将单播 UDP 转发到多播组,或者只是将数据保存到文件中并稍后处理.

You should be able to use socat to forward unicast UDP to a multicast group, or just save data into a file and process later.

这是一个示例(这是在 Linux 上 - 没有任何 Windows 机器).监听单播端口4242,转发到多播224.10.10.10:5252(如果你是,你可能需要添加ip-multicast-loop选项在同一台机器上做所有事情):

Here is an example (this is on Linux - don't have any Windows boxes). Listen on unicast port 4242, forward to multicast 224.10.10.10:5252 (you might have to add ip-multicast-loop option if you are doing everything on the same machine):

~$ socat UDP-LISTEN:4242 UDP-DATAGRAM:224.10.10.10:5252

接收多播(需要接口地址或名称),转发到单播192.168.0.1:6666:

Receive on multicast (needs interface address or name), forwards to unicast 192.168.0.1:6666:

~$ socat UDP-RECVFROM:5252,ip-add-membership=224.10.10.10:eth0,reuseaddr,fork 
   UDP-DATAGRAM:192.168.0.1:6666

使用不同的目标地址运行上述两个(reuseaddr 选项允许它们在同一台机器上运行).

Run two of the above with different destination addresses (reuseaddr option allows these to be run on the same machine).