How to receive the same udp-stream in several programs?

让人想犯罪 __ 提交于 2019-12-06 10:40:20

问题


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.


回答1:


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.

Edit 0:

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

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

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



来源:https://stackoverflow.com/questions/12564580/how-to-receive-the-same-udp-stream-in-several-programs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!