dotnet / MQTTnet

MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.
MIT License
4.46k stars 1.06k forks source link

Client: ConnectAsync not connecting Android Maui while in Windows connect #1844

Open AhmedKhalil777 opened 1 year ago

AhmedKhalil777 commented 1 year ago

The mqttclient throws (Socket Exception: Connection refused) exception on Connecting to mqtt broker while it can connect on Windows version of same app.

The same issue happens on the Emulator and also a regular device

Stack Trace

MQTTnet.Exceptions.MqttCommunicationException: Error while connecting with host '192.168.1.110:1833'.
 ---> System.Net.Sockets.SocketException (111): Connection refused
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|281_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
   at MQTTnet.Implementations.CrossPlatformSocket.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at MQTTnet.Implementations.CrossPlatformSocket.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   at MQTTnet.Implementations.MqttTcpChannel.ConnectAsync(CancellationToken cancellationToken)
   at MQTTnet.Adapter.MqttChannelAdapter.ConnectAsync(CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectInternal(IMqttChannelAdapter channelAdapter, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(MqttClientOptions options, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(MqttClientOptions options, CancellationToken cancellationToken)
   at IoTunnel.Client.Infrastructure.Mqtt.MQTTBase.CheckConnectivity() in D:\Projects\IoTunnel\IoTunnel.ConnectivityHub\src\IoTunnel.Client.Infrastructure.Mqtt\MQTTBase.cs:line 35
   at IoTunnel.Client.Infrastructure.Mqtt.MQTTProducer.<Produce>d__1`1[[IoTunnel.Protos.Models.DeviceConfig, IoTunnel.Protos, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() in D:\Projects\IoTunnel\IoTunnel.ConnectivityHub\src\IoTunnel.Client.Infrastructure.Mqtt\MQTTProducer.cs:line 16
   at IoTunnel.App.Pages.Testing.MqttTestingComponent.ProduceMessage() in D:\Projects\IoTunnel\IoTunnel.ConnectivityHub\src\IoTunnel.App\Pages\Testing\MqttTestingComponent.razor:line 80
chkr1011 commented 11 months ago

This is probably more a topic for the MAUI Team because we just use Sockets from the .NET Framework and have little to no platform dependant code (UWP only).

Which platform does not work? Android or iOS?