Code Monkey home page Code Monkey logo

Comments (4)

davidepianca98 avatar davidepianca98 commented on June 4, 2024 1

Sorry I missed the broker part. I have replicated your exact setup with the same code. Then I run it on an Android 14 emulator.
I used this command to forward the port from the host PC to the emulator: .\adb.exe forward tcp:1883 tcp:1883
And then I use MQTT X to connect and it works.

Please check again and make sure that the client is setup to use TLS, because I get that same error when I try to connect with MQTT X (the client) with TLS disabled.

from kmqtt.

davidepianca98 avatar davidepianca98 commented on June 4, 2024

Hello, this usually happens if you are trying to connect to the broker port where there is no TLS setup. Please check that.
Also can you please post the MQTTClient constructor without sensitive information?
Can you reproduce the problem on a public broker like test.mosquitto.org so that I can try it?
Which version of Android are you running on, are you on an emulator and if yes which device?

from kmqtt.

nishankhadka09 avatar nishankhadka09 commented on June 4, 2024

This issue is when I am using the kmqtt-broker library. I haven't tried the client library yet. I used the kmqtt-broker lib to create my own standalone broker, which works fine when there is no TLS enabled. But when I enable TLS, the broker.listen() throws the mentioned exception.
Android version - 13 & 14 (Tiramisu and UpsideDown cake)

broker constructor

 broker = Broker(
                tlsSettings = if (isTlsEnabled) TLSSettings(keyStoreFilePath = getTlsFilepath(), keyStorePassword = "P@ss")else null,
                authentication = if (authenticationNeeded) {
                    object : Authentication {
                        override fun authenticate(
                            clientId: String,
                            username: String?,
                            password: UByteArray?
                        ): Boolean {
                            return username == mqttUserName && password?.toByteArray()
                                ?.decodeToString() == mqttPassword
                        }
                    }
                } else null,
                connectionCallbacks = connectionCallbacks, bytesMetrics = bytesMetrics,
            )
            broker.listen()

private fun getTlsFilepath(): String {
       val inputStream = application.resources.openRawResource(R.raw.mqtt_test_cert)
       val file = File.createTempFile("keyStore", ".p12", application.cacheDir)
       val outputStream = FileOutputStream(file)
       inputStream.use { input ->
           outputStream.use { output ->
               input.copyTo(output)
           }
       }
       Timber.d("File path is ${file.absolutePath}")
       return file.absolutePath

   }

from kmqtt.

nishankhadka09 avatar nishankhadka09 commented on June 4, 2024

Thank you! Client wasn't set up properly, fixed it and it's working.

from kmqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.