MQTTnet.Exception.MqttCommunicationTimeOutException

See original GitHub issue

I met a MqttCommunicationTimeOutException, but I’m not sure what the problem, hope to be able to get help. Version 3.0.5 is used.

This is the exception information:

MQTTnet.Exceptions.MqttCommunicationTimedOutException: Exception of type 'MQTTnet.Exceptions.MqttCommunicationTimedOutException' was thrown.
   at MQTTnet.PacketDispatcher.MqttPacketAwaiter`1.WaitOneAsync(TimeSpan timeout)
   at MQTTnet.Client.MqttClient.SendAndReceiveAsync[TResponsePacket](MqttBasePacket requestPacket, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.PublishAtLeastOnceAsync(MqttPublishPacket publishPacket, CancellationToken cancellationToken)

This is considered critical code:

MqttClient.UseApplicationMessageReceivedHandler(e =>
{
    MqttClient_ApplicationMessageReceived(e);
});

private void MqttClient_ApplicationMessageReceived(MqttApplicationMessageReceivedEventArgs e)
{
    Console.WriteLine("### 从服务端接收的消息 ###");
    Console.WriteLine($"+ Topic = {e.ApplicationMessage.Topic}");
    Console.WriteLine($"+ Payload = {Encoding.UTF8.GetString(e.ApplicationMessage.Payload)}");
    Console.WriteLine();

    // After processing, the theme is republished
    Event_MQTTMessageReceived?.Invoke(e);
}

public void Publish(string topic, string Data)
{
    if (MqttClient != null && MqttClient.IsConnected)
    {
        var _Message = new MqttApplicationMessageBuilder();
        _Message.WithTopic(topic);
        _Message.WithPayload(Data);
        _Message.WithAtMostOnceQoS();
        _Message.WithRetainFlag(false);

        MqttClient.PublishAsync(_Message.Build());

        Console.WriteLine("### 从本地发送的消息 ###");
        Console.WriteLine($"+ Topic = {topic}");
        Console.WriteLine($"+ Payload = {Data}");
        Console.WriteLine();
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
jingsong-liucommented, Oct 28, 2020

My question is solved. The cause is that client has possibility of unsubscribing topic after disconnected.

0reactions
SeppPennercommented, Oct 27, 2020

@chkr1011 I will re-open this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MQTTnet.Exception.MqttCommunicationTimeOutException
Version 3.0.5 is used. This is the exception information:. MQTTnet.Exceptions.MqttCommunicationTimedOutException: Exception of type 'MQTTnet.
Read more >
c# - MQTTnet PublishAsync Exception
I'm trying to use "MQTTnet" in a Xamarin application. ... well, it publishs but after about 5 seconds it throw the following exception...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found