asConnection

suspend fun Pair<ByteReadChannel, ByteWriteChannel>.asConnection(env: KsrpcEnvironment<String>): Connection<String>

Create a Connection for the given input/output channel.

Samples

val env = ksrpcEnvironment { }

// Create a pair of byte channels (simulating a socket pair).
val readChannel = ByteChannel(autoFlush = true)
val writeChannel = ByteChannel(autoFlush = true)

// Any Pair<ByteReadChannel, ByteWriteChannel> can become a Connection.
val connection = (readChannel to writeChannel).asConnection(env)

// Register a service on the connection.
val service = object : GreetingService {
    override suspend fun greet(name: String): String = "Hello, $name!"
}
connection.registerDefault(service.serialized(env))

fun Pair<ByteReadChannel, ByteWriteChannel>.asConnection(scope: CoroutineScope, env: KsrpcEnvironment<String>): Connection<String>

Create a Connection for the given input/output channel using a caller-provided scope.

Helper that calls into Pair.asConnection.


Create a Connection that starts the process and uses the Process.getInputStream and Process.getOutputStream as the streams for communication