static void Main(string[] args) { MqttNetTrace.TraceMessagePublished += MqttNetTrace_TraceMessagePublished; new Thread(StartMqttServer).Start(); while (true) { var inputString = Console.ReadLine().ToLower().Trim(); if (inputString == "exit") { mqttServer?.StopAsync(); Console.WriteLine("MQTT服务已停止!"); break; } else if (inputString == "clients") { foreach (var item in mqttServer.GetConnectedClients()) { Console.WriteLine($"客户端标识:{item.ClientId},协议版本:{item.ProtocolVersion}"); } } else { Console.WriteLine($"命令[{inputString}]无效!"); } } }
static void Main(string[] args) { new Thread(StartMqttServer).Start(); while (true) { var inputString = Console.ReadLine().ToLower().Trim(); if (inputString == "exit") { mqttServer?.StopAsync().Wait(); Console.WriteLine("MQTT服务已停止!"); break; } else if (inputString == "clients") { foreach (var item in mqttServer.GetClientSessionsStatus())//客户端session { Console.WriteLine($"客户端标识:{item.ClientId},协议版本:{item.ProtocolVersion}"); } } else { Console.WriteLine($"命令[{inputString}]无效!"); } } }