【问题标题】:Reading UDP datagrams from GNSS receiver从 GNSS 接收器读取 UDP 数据报
【发布时间】:2020-08-29 09:23:14
【问题描述】:

我正在尝试将来自 Airlink MP70 GNSS 网关的位置数据读取到模拟控制台应用程序中。 GNSS 语句通过以太网和 UDP 发送到我的计算机。

网关 IP:192.168.13.31(GNSS 接收器) 源端口:17335

目标 IP:192.168.13.100 端口:12351

我可以使用wireshark 看到UDP 数据报。突出显示的区域是我要提取的 GNSS 数据。

我如何将这些数据接收到一个基本的控制台应用程序中,最好是 c#,但 c++/java python 也可以。

这是我目前所拥有的,但我没有看到任何输出(它只是 Microsoft c# 站点上 UDP 客户端的基本代码)。

 private const int listenPort = 12351;

        public static void Main()
        {
            UdpClient receivingUdpClient = new UdpClient(listenPort);

            //Creates an IPEndPoint to record the IP Address and port number of the sender.
            // The IPEndPoint will allow you to read datagrams sent from any source.
            IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
            try
            {

                // Blocks until a message returns on this socket from a remote host.
                Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);

                string returnData = Encoding.ASCII.GetString(receiveBytes);

                Console.WriteLine("This is the message you received " +
                                          returnData.ToString());
                Console.WriteLine("This message was sent from " +
                                            RemoteIpEndPoint.Address.ToString() +
                                            " on their port number " +
                                            RemoteIpEndPoint.Port.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }

【问题讨论】:

  • 你运行这个时发生了什么?
  • 绝对没有 - 我猜它阻塞接收等待数据
  • 你能通过在调试器中单步执行来验证吗?
  • 是的,它阻塞了 Receive 方法 - 创建了接收 UdpClient ok
  • 您的程序在阅读一条消息后终止。尝试将代码放入 While(true){ } 循环。

标签: c# sockets udp ip


【解决方案1】:

我的坏处是防火墙阻止了连接。感谢那些帮助过的人

【讨论】:

    猜你喜欢
    • 2014-05-14
    • 2011-05-13
    • 1970-01-01
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-14
    相关资源
    最近更新 更多