接收UDP流,然后本地转发

问题描述

看着https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.udpclient?view=netcore-3.1

我从外部网络接收到UDP流并对其进行处理。现在,我想将其发送到本地设备。

例如,我有数据进入127.0.0.1:9001,并希望将其发送到位于192.168.0.101:9002的另一台计算机上。

我已经尝试了以下循环(已修改以创建MVE),但是通过Wireshark无法看到任何内容。我是否缺少某些内容,或者在.net中无法实现?

    private udpClient udpListener;
    
    udpListener = new UdpClient(9001);
    IPEndPoint listenerEndPoint = new IPEndPoint(IPAddress.Any,9001);
    Byte[] message = udpListener.Receive(ref listenerEndPoint);

    Console.WriteLine(Encoding.UTF8.GetString(message));

    IPAddress ipAddress = new IPAddress(new byte[] { 192,168,100 });
    int port = 9002;

    UdpClient client = new UdpClient();
    client.Connect(new System.Net.IPEndPoint(ipAddress,port));

    client.Send(message,message.Length);

为了对此进行测试,我使用ffmpeg将mp4发送到udp,然后在接收器端进行wireshark / ffplay。


Sending UDP messages works,receiving not - C# on Unity3d

我找到了上面的问题,但遗憾的是最后是一个python解决方案,我更愿意坚持使用.net核心。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)