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.
 
 
 
 

28 line
793 B

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