startListening

fun startListening(onMessage: (message: String, senderAddress: InetAddress) -> Unit): Result<Unit>(source)

Starts a background thread that blocks on listenSocket's receive, decoding each incoming datagram as a UTF-8 string and passing it to onMessage along with the sender's address.

Return

Result.success once the listener thread is running, or Result.failure if the thread could not be started

Parameters

onMessage

invoked on the listener thread for every datagram received