internal MqttTransportHandler(IotHubConnectionString iotHubConnectionString, MqttTransportSettings settings) { this.DefaultReceiveTimeout = DefaultReceiveTimeoutInSeconds; this.connectCompletion = new TaskCompletionSource(); this.mqttIotHubAdapterFactory = new MqttIotHubAdapterFactory(settings); this.messageQueue = new ConcurrentQueue<Message>(); this.completionQueue = new Queue<string>(); this.serverAddress = Dns.GetHostEntry(iotHubConnectionString.HostName).AddressList[0]; var group = new SingleInstanceEventLoopGroup(); this.qos = settings.PublishToServerQoS; this.bootstrap = new Bootstrap() .Group(@group) .Channel<TcpSocketChannel>() .Option(ChannelOption.TcpNodelay, true) .Handler(new ActionChannelInitializer<ISocketChannel>(ch => { ch.Pipeline.AddLast( TlsHandler.Client(iotHubConnectionString.HostName, null), MqttEncoder.Instance, new MqttDecoder(false, 256 * 1024), this.mqttIotHubAdapterFactory.Create( this.OnConnected, this.OnMessageReceived, this.OnError, iotHubConnectionString, settings)); })); this.ScheduleCleanup(async () => { this.connectCompletion.TrySetCanceled(); await group.ShutdownGracefullyAsync(); }); }
internal MqttTransportHandler(IotHubConnectionString iotHubConnectionString, MqttTransportSettings settings) { this.DefaultReceiveTimeout = DefaultReceiveTimeoutInSeconds; this.connectCompletion = new TaskCompletionSource(); this.mqttIotHubAdapterFactory = new MqttIotHubAdapterFactory(settings); this.messageQueue = new ConcurrentQueue <Message>(); this.completionQueue = new Queue <string>(); this.serverAddress = Dns.GetHostEntry(iotHubConnectionString.HostName).AddressList[0]; var group = new SingleInstanceEventLoopGroup(); this.qos = settings.PublishToServerQoS; this.bootstrap = new Bootstrap() .Group(@group) .Channel <TcpSocketChannel>() .Option(ChannelOption.TcpNodelay, true) .Handler(new ActionChannelInitializer <ISocketChannel>(ch => { ch.Pipeline.AddLast( TlsHandler.Client(iotHubConnectionString.HostName, null), MqttEncoder.Instance, new MqttDecoder(false, 256 * 1024), this.mqttIotHubAdapterFactory.Create( this.OnConnected, this.OnMessageReceived, this.OnError, iotHubConnectionString, settings)); })); this.ScheduleCleanup(async() => { this.connectCompletion.TrySetCanceled(); await group.ShutdownGracefullyAsync(); }); }