Skip to content

Instantly share code, notes, and snippets.

@LethalMaus
Created February 11, 2026 19:58
Show Gist options
  • Select an option

  • Save LethalMaus/1920acde7fe40501054c9d25e73348fe to your computer and use it in GitHub Desktop.

Select an option

Save LethalMaus/1920acde7fe40501054c9d25e73348fe to your computer and use it in GitHub Desktop.
ZeroMq.kt
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import org.zeromq.SocketType
import org.zeromq.ZContext
import org.zeromq.ZMQ
import org.zeromq.ZMQException
import java.io.Closeable
class ZeroMqClient(
private val subPort: Int? = null, // eg. 54054,
private val pubPort: Int? = null, // eg. 54055,
private val messageCallback: ((String) -> Unit)? = null,
private val onConnectionChanged: ((Boolean) -> Unit)? = null
) : Closeable {
private var context: ZContext? = null
private var subSocket: ZMQ.Socket? = null
private var pubSocket: ZMQ.Socket? = null
private var isRunning = false
private var receiveJob: Job? = null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment