如何在多个程序中接收相同的udp流? [英] How to receive the same udp-stream in several programs?

查看:174
本文介绍了如何在多个程序中接收相同的udp流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个封闭的第三方系统,该系统发送一个单播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).

这篇关于如何在多个程序中接收相同的udp流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆