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.

MqttClientFactory.cs 1.1 KiB

7 jaren geleden
7 jaren geleden
7 jaren geleden
7 jaren geleden
7 jaren geleden
7 jaren geleden
7 jaren geleden
7 jaren geleden
7 jaren geleden
12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using MQTTnet.Core.Adapter;
  3. using MQTTnet.Core.Client;
  4. using MQTTnet.Core.Serializer;
  5. using MQTTnet.Implementations;
  6. using MQTTnet.Core.Channel;
  7. namespace MQTTnet
  8. {
  9. public class MqttClientFactory
  10. {
  11. public IMqttClient CreateMqttClient(MqttClientOptions options)
  12. {
  13. if (options == null) {
  14. throw new ArgumentNullException(nameof(options));
  15. }
  16. return new MqttClient(options, new MqttChannelCommunicationAdapter(GetMqttCommunicationChannel(options), new MqttPacketSerializer()));
  17. }
  18. private static IMqttCommunicationChannel GetMqttCommunicationChannel(MqttClientOptions options)
  19. {
  20. switch (options.ConnectionType)
  21. {
  22. case MqttConnectionType.Tcp:
  23. case MqttConnectionType.Tls:
  24. return new MqttTcpChannel();
  25. case MqttConnectionType.Ws:
  26. case MqttConnectionType.Wss:
  27. return new MqttWebSocketChannel();
  28. default:
  29. throw new NotSupportedException();
  30. }
  31. }
  32. }
  33. }