您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

35 行
1.1 KiB

  1. using System;
  2. using System.Net;
  3. using MQTTnet.Adapter;
  4. using MQTTnet.AspNetCore.Client.Tcp;
  5. using MQTTnet.Client;
  6. using MQTTnet.Diagnostics;
  7. using MQTTnet.Serializer;
  8. namespace MQTTnet.AspNetCore.Client
  9. {
  10. public class MqttClientConnectionContextFactory : IMqttClientAdapterFactory
  11. {
  12. public IMqttChannelAdapter CreateClientAdapter(IMqttClientOptions options, IMqttNetChildLogger logger)
  13. {
  14. if (options == null) throw new ArgumentNullException(nameof(options));
  15. var serializer = new MqttPacketSerializer { ProtocolVersion = options.ProtocolVersion };
  16. switch (options.ChannelOptions)
  17. {
  18. case MqttClientTcpOptions tcpOptions:
  19. {
  20. var endpoint = new DnsEndPoint(tcpOptions.Server, tcpOptions.GetPort());
  21. var tcpConnection = new TcpConnection(endpoint);
  22. return new MqttConnectionContext(serializer, tcpConnection);
  23. }
  24. default:
  25. {
  26. throw new NotSupportedException();
  27. }
  28. }
  29. }
  30. }
  31. }