以下是我的代码示例。它不起作用。我以正确的形式{0x01}发送了确认,但设备始终只返回IMEI。有人能解决这个问题吗?
static void Main(string[] args)
{
TcpListener list = new TcpListener(new IPEndPoint(IPAddress.Any, 2065));
TcpClient client;
Console.WriteLine("Listening... \n");
list.Start(1);
list.Server.NoDelay = true;
while (true)
{
Console.WriteLine("Waiting for client...\n");
client = list.AcceptTcpClient();
Console.WriteLine("Client connected ");
byte[] imei = new byte[8192];
NetworkStream ns = client.GetStream();
if (ns.CanRead)
{
ns.Read(imei, 0, (int)client.ReceiveBufferSize);
}
Console.WriteLine(Encoding.ASCII.GetString(imei, 0, imei.Length));
byte[] ack = new byte[1] {0x01};
if (ns.CanWrite)
{
ns.Write(ack, 0, ack.Length);
}
client.Close();
}
}
答案 0 :(得分:0)