TcpTransport

class TcpTransport(dispatchers: CoroutineDispatchers, scope: CoroutineScope, listener: TcpTransport.Listener, logTag: String = "TcpTransport")(source)

Shared TCP transport for Meshtastic radios.

Manages the TCP socket lifecycle (connect, read loop, reconnect with backoff) and uses StreamFrameCodec for the START1/START2 stream framing protocol. sendHeartbeat sends a heartbeat with a monotonically-increasing nonce so the firmware's per-connection duplicate-write filter does not silently drop it.

Uses Ktor raw sockets (ktor-network) so the implementation is KMP-common — shared by Android, Desktop, and (once wired) iOS via the shared SharedRadioInterfaceService.

Constructors

Link copied to clipboard
constructor(dispatchers: CoroutineDispatchers, scope: CoroutineScope, listener: TcpTransport.Listener, logTag: String = "TcpTransport")

Types

Link copied to clipboard
object Companion
Link copied to clipboard
interface Listener

Callbacks from the transport to the owning radio interface.

Properties

Link copied to clipboard

Whether the transport is currently connected.

Functions

Link copied to clipboard
suspend fun sendHeartbeat()

Send a heartbeat packet with a monotonically-increasing nonce to keep the connection alive. Starts at HeartbeatSender.FIRST_NONCE, past the firmware's NodeInfo-ping trigger.

Link copied to clipboard
suspend fun sendPacket(payload: ByteArray)

Send a raw framed Meshtastic packet.

Link copied to clipboard
fun start(address: String)

Start a TCP connection to the given address with automatic reconnect.

Link copied to clipboard
fun stop()

Stop the transport and close the socket.