A Kotlin Multiplatform, coroutine-based MQTT client library
implementation("it.nicolasfarabegoli:mktt:<version>")
or using Gradle catalogs:
[versions]
mktt-version = "<version>"
[dependencies]
mktt = { module = "it.nicolasfarabegoli:mktt", version.ref = "mktt-version" }
val mqttClient = MkttClient(Dispatchers.IO) {
brokerUrl = "localhost"
port = 1883
clientId = "mktt-client"
}
mqttClient.connect()
mqttClient.publish(
topic = "test/topic",
qos = MqttQoS.ExactlyOnce,
"hello world".encodeToByteArray(),
)
mqttClient.disconnect()
val mqttClient = MkttClient(Dispatchers.IO) {
brokerUrl = "localhost"
port = 1883
clientId = "mktt-client"
}
mqttClient.connect()
mqttClient.subscribe("test/topic", MqttQoS.ExactlyOnce).collect {
println("Received message: ${it.payload.decodeToString()}")
}
mqttClient.disconnect()
Platform | Target | Description | Supported |
---|---|---|---|
JVM | jvm() |
Java Virtual Machine (backend, desktop apps) | ✅ |
Android | android() |
Native Android development | ✅ |
iOS | ios() , iosArm64() , iosX64() , iosSimulatorArm64() |
Apple iOS devices (real & simulator) | ❌ |
macOS | macosX64() , macosArm64() |
macOS applications | ❌ |
watchOS | watchosX64() , watchosArm64() , watchosSimulatorArm64() |
Apple Watch apps | ❌ |
tvOS | tvosX64() , tvosArm64() , tvosSimulatorArm64() |
Apple TV apps | ❌ |
Linux | linuxX64() , linuxArm64() , linuxArm32Hfp() |
Linux native applications | ❌ |
Windows | mingwX64() |
Windows native applications | ❌ |
Web | js() |
JavaScript (both browser & Node.js) | ✅ |
Wasm | wasmJs() , wasmWasi() |
WebAssembly (browser & standalone) | ❌ |
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
See the LICENSE file for more details.