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.
 
 
 
 

39 lines
1.4 KiB

  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using MQTTnet.Adapter;
  5. using MQTTnet.AspNetCore.Client.Tcp;
  6. using MQTTnet.Formatter;
  7. using System;
  8. using System.Net;
  9. using MQTTnet.Client;
  10. using MQTTnet.Diagnostics;
  11. namespace MQTTnet.AspNetCore.Client
  12. {
  13. public sealed class MqttClientConnectionContextFactory : IMqttClientAdapterFactory
  14. {
  15. public IMqttChannelAdapter CreateClientAdapter(MqttClientOptions options, MqttPacketInspector packetInspector, IMqttNetLogger logger)
  16. {
  17. if (options == null) throw new ArgumentNullException(nameof(options));
  18. switch (options.ChannelOptions)
  19. {
  20. case MqttClientTcpOptions tcpOptions:
  21. {
  22. var endpoint = new DnsEndPoint(tcpOptions.Server, tcpOptions.GetPort());
  23. var tcpConnection = new TcpConnection(endpoint);
  24. var formatter = new MqttPacketFormatterAdapter(options.ProtocolVersion, new MqttBufferWriter(4096, 65535));
  25. return new MqttConnectionContext(formatter, tcpConnection);
  26. }
  27. default:
  28. {
  29. throw new NotSupportedException();
  30. }
  31. }
  32. }
  33. }
  34. }