hivemq / hivemq-mqtt-client

HiveMQ MQTT Client is an MQTT 5.0 and MQTT 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support
https://hivemq.github.io/hivemq-mqtt-client/
Apache License 2.0
860 stars 159 forks source link

Connection to mqtt server failed! (recvfrom failed) #493

Closed amindadgar closed 1 year ago

amindadgar commented 3 years ago

Expected behavior

Connect to the MQTT server with no problem and publish two messages, one with the topic AndroidApp and the other in publish function. Log:

D/MQttConnectionClass: connectTOmqtt: Completed Connecting

Actual behavior

Could not connect to the MQTT server and log the below texts.

D/MQttConnectionClass: connectTOmqtt: Error Connecting server
D/MQttConnectionClass: connectTOmqtt: Error, java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
D/MQttConnectionClass: connectTOmqtt: kotlin.Unit

To Reproduce

Just running the code.

Steps

compile and run the code on my galaxy mini s5570, with custom rom cyanogen mod ( Android 4.4.2 ).

Reproducer code

val uniqueIdentifier = android.os.Build.BRAND + android.os.Build.MODEL + "sample identifier"
        Mqtt5Client = clientBuilder.identifier(uniqueIdentifier)
            .serverHost("192.168.1.9")
            .serverPort("1883")
            // use mqtt version 5
            .useMqttVersion5()
            .sslWithDefaultConfig()
            .buildAsync()

Mqtt5Client.connectWith()
            .cleanStart(false) // resume the previous session
            .noSessionExpiry()  // Session Would never be expired
            .willPublish()
                .topic("AndroidApp")
                .qos(MqttQos.EXACTLY_ONCE)
                .payload("$deviceInfo Connected!".encodeToByteArray())
                .contentType("text/plain")  // our payload is text
                .applyWillPublish()
            .send()
                .whenComplete { mqtt5ConnAck, throwable ->
                    if (throwable != null) {
                        Log.d(TAG, "connectTOmqtt: Error Connecting server")
                        Log.d(TAG, "connectTOmqtt: Error, ${throwable.message}")
                        Log.d(TAG, "connectTOmqtt: ${throwable.printStackTrace()}")
                    }
                    else {
                        Log.d(TAG, "connectTOmqtt: Completed Connecting")
                        // If successfully connected go and publish some message
                        publish()
                    }
                }

Details

Note that My arduino boards are communicating perfectly with my MQTT server. ( raspberry pi server is local ) Also I have checked another application using org.eclipse.paho.client.mqttv3 for another app it was working with no problem with my galaxy mini phone. ( The problem with the last library was it keeps disconnecting after some time )

Any help would be appreciated 🙂

SgtSilvio commented 3 years ago

Hi @amindadgar Sorry for the delayed response. You seam to use SSL/TLS (.sslWithDefaultConfig()) but connect to port 1883. MQTT over SSL/TLS usually uses port 8883. This might be the cause for your connection reset.

pglombardo commented 1 year ago

Hi @amindadgar - since this issue hasn't had any updates, I will close it out. If this issue (or another) still exists, feel free to file a new one and we'd be happy to help out!