Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTTnet.Exceptions.MqttCommunicationTimedOutException HResult=0x80131500 Message=The operation has timed out. Source=mscorlib StackTrace: at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in System.Runtime.CompilerServices\TaskAwaiter.cs:line 78 此异常最初是在此调用堆栈中引发的: #1921

Open
shiyuanGame opened this issue Feb 4, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@shiyuanGame
Copy link

image
image

尊敬的开发者,您好,我在使用mqtt协议遇到了问题,我在发布消息端 发布在 while true 内 push message sleep 100毫秒 一分钟以内必报错这个异常bug 超时 一下是客户端订阅代码

public class MosquittoClient
{

 string test_topic= "test_topic";
 string ip = "10.17.17.74";
 public string Test_topic{ get => test_topic; set => test_topic= value; }
 public MosquittoClient()
 {
     init();
 }
 private async void init()
 {

     var logger = new MqttNetEventLogger();

     var factory = new MqttFactory(logger);
     var client = factory.CreateMqttClient();
     var clientOptions = new MqttClientOptions
     {
         ChannelOptions = new MqttClientTcpOptions
         {
             Server = ip,
             Port = 1883
         }
         ,
         Timeout = TimeSpan.FromSeconds(20)
     };

     client.ApplicationMessageReceivedAsync += e =>
     {
         var payloadText = string.Empty;
         if (e.ApplicationMessage.PayloadSegment.Count > 0)
         {
             payloadText = Encoding.UTF8.GetString(
                  e.ApplicationMessage.PayloadSegment.Array,
                  e.ApplicationMessage.PayloadSegment.Offset,
                  e.ApplicationMessage.PayloadSegment.Count);
                  Console.WriteLine(payloadText); 
         }
         return CompletedTask.Instance;
     };

     client.ConnectedAsync += async e =>
     {
         Console.WriteLine("### CONNECTED WITH SERVER ###");

         await client.SubscribeAsync(Test_topic);

         Console.WriteLine("### SUBSCRIBED ###");
     };

     client.DisconnectedAsync += async e =>
     {
         Console.WriteLine("### DISCONNECTED FROM SERVER ###");
         await Task.Delay(TimeSpan.FromSeconds(5));

         try
         {
             await client.ConnectAsync(clientOptions);
         }
         catch
         {
             Console.WriteLine("### RECONNECTING FAILED ###");
         }
     };

     try
     {
         await client.ConnectAsync(clientOptions);
     }
     catch (Exception exception)
     {
         Console.WriteLine("### CONNECTING FAILED ###" + Environment.NewLine + exception);
     }
 }

}

@shiyuanGame shiyuanGame added the bug Something isn't working label Feb 4, 2024
@shiyuanGame
Copy link
Author

shiyuanGame commented Feb 4, 2024

补充 版本
image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant