connect
Opens a Connection to the native host on the given scope: it builds the connection, invokes initialize (the consumer's native binding) so the host's setup lambda runs against this connection (building its own per-connection native environment and service instance(s)), and returns it ready to use. Each call is independent -- nothing is shared across connections.
initialize is the consumer's native entry point, usually a reference to an external fun on one of their classes (e.g. MyNativeService::initialize) that forwards its JniHostInit to com.monkopedia.ksrpc.jni.ksrpcHostConnection. The JniHostInit is an opaque bundle of the per-connection JNI context; the consumer never unpacks it.
The connection uses JniSerialization; the optional environment configures the JVM-side KsrpcEnvironment (logger, error listener, ...). The native side builds its own per-connection environment, configured via the configure block passed to ksrpcHostConnection.
Samples
import com.monkopedia.ksrpc.jni.JniHostInit
import com.monkopedia.ksrpc.jni.JniSerialized
import com.monkopedia.ksrpc.jni.KsrpcNativeHost
import com.monkopedia.ksrpc.jni.NativeUtils
import com.monkopedia.ksrpc.toStub
import kotlinx.coroutines.CoroutineScope
fun main() {
//sampleStart
// Load the Kotlin/Native shared library bundled on the classpath (once per process).
NativeUtils.loadLibraryFromJar("/libs/libksrpc_samples.so")
// connect() invokes MyNativeService::initialize, which drives the native
// `ksrpcHostConnection` to build this connection's environment and register
// its service before returning a connection ready to use.
val connection = KsrpcNativeHost.connect(scope, MyNativeService::initialize)
// Use the connection.
val service = connection.defaultChannel().toStub<GreetingService, JniSerialized>()
val greeting = service.greet("world")
//sampleEnd
}