0

我使用 UDP 连接将数据传输到服务器上的程序。数据由 Quectel BC66 的调制解调器传输。来自终端的 AT 命令如下所示:

AT+QISEND=0,20,12345678910111213112

OK

SEND OK

当数据出现在服务器上而不是显示发送的数据时,它会显示问号:

在此处输入图像描述

该程序的代码如下所示:

class Program
    {
        static void Main(string[] args)
        {
            try
            {
                IPEndPoint ip = new IPEndPoint(IPAddress.Any, 29030);
                UdpClient server = new UdpClient(ip);
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("[UDP] [Listenning]");
                while (true)
                {
                    byte[] data = server.Receive(ref ip);
                    string ch = Encoding.Unicode.GetString(data, 0, data.Length);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine(ch + " " + DateTime.Now.ToString());
                    string serv_msg = "Server received the data";
                    byte[] msg = Encoding.Unicode.GetBytes(serv_msg);
                    server.Send(msg, msg.Length, ip);
                    server.Send(new byte[] { 1 }, 1, ip);
                }
            }
            catch
            {
                Console.WriteLine("Warrning:connection failed");
                Console.ReadKey();
            }
        }
    }
}

您对如何在服务器程序上显示相同的发送数据有任何建议吗?

4

1 回答 1

0

您的终端应用程序似乎不支持您尝试显示的 Unicode 字符。

尝试更改您的设置以允许使用 unicode 字符或切换到另一个终端模拟器,例如ConEmu

希望这可以帮助!

于 2019-09-30T09:13:27.683 回答