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