MqttTransport

interface MqttTransport

Abstract byte-level transport for MQTT connections.

This is the sole platform abstraction boundary in the library. Implementations:

  • TcpTransport in nonWebMain — raw TCP sockets via ktor-network (JVM, Android, iOS, macOS, Linux, Windows)

  • WebSocketTransport in nonWebMain — binary WebSocket frames via ktor-client-websockets (JVM, Android, iOS, macOS, Linux, Windows)

  • WebSocketTransport in wasmJsMain — binary WebSocket frames via ktor-client-websockets (browser)

This is a published service-provider interface (SPI): transport modules implement it and supply an instance through MqttConfig.Builder.transportFactory. Most consumers never touch it directly — they pick a transport module and use MqttClient.

Properties

Link copied to clipboard
abstract val isConnected: Boolean

Whether the transport is currently connected.

Functions

Link copied to clipboard
abstract suspend fun close()

Close the transport connection.

Link copied to clipboard
abstract suspend fun connect(endpoint: MqttEndpoint)

Establish a connection to the broker.

Link copied to clipboard
abstract suspend fun receive(): ByteArray

Receive one complete MQTT packet as raw bytes.

Link copied to clipboard
abstract suspend fun send(bytes: ByteArray)

Send raw bytes over the transport.