You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

31 lines
908 B

  1. using System.Threading;
  2. using System.Threading.Tasks;
  3. using MQTTnet.Client;
  4. using MQTTnet.Client.Options;
  5. using MQTTnet.Diagnostics;
  6. using MQTTnet.Server;
  7. namespace MQTTnet.TestApp.NetCore
  8. {
  9. public static class ServerAndClientTest
  10. {
  11. public static async Task RunAsync()
  12. {
  13. var logger = new MqttNetLogger();
  14. MqttNetConsoleLogger.ForwardToConsole(logger);
  15. var factory = new MqttFactory(logger);
  16. var server = factory.CreateMqttServer();
  17. var client = factory.CreateMqttClient();
  18. var serverOptions = new MqttServerOptionsBuilder().Build();
  19. await server.StartAsync(serverOptions);
  20. var clientOptions = new MqttClientOptionsBuilder().WithTcpServer("localhost").Build();
  21. await client.ConnectAsync(clientOptions);
  22. await Task.Delay(Timeout.Infinite);
  23. }
  24. }
  25. }