我使用 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();
}
}
}
}
您对如何在服务器程序上显示相同的发送数据有任何建议吗?