hivemq-mqtt-client icon indicating copy to clipboard operation
hivemq-mqtt-client copied to clipboard

Connection to mqtt server failed! (recvfrom failed)

Open amindadgar opened this issue 4 years ago • 1 comments

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

  • Affected HiveMQ MQTT Client version(s): 1.2.2
  • Used JVM version: 1.8
  • Used OS (name and version): Cyanogen mod android 4.4.2
  • Used MQTT version: version 5
  • Used MQTT broker (name and version): mosquitto
  • Server OS: Raspbian

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 🙂

amindadgar avatar Jul 10 '21 07:07 amindadgar

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.

SgtSilvio avatar Aug 02 '21 20:08 SgtSilvio

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!

pglombardo avatar Mar 07 '23 14:03 pglombardo