asConnection
suspend fun Pair<ByteReadChannel, ByteWriteChannel>.asConnection(env: KsrpcEnvironment<String>): Connection<String>
Create a Connection for the given input/output channel.
Samples
import com.monkopedia.ksrpc.channels.connect
import com.monkopedia.ksrpc.ksrpcEnvironment
import com.monkopedia.ksrpc.serialized
import com.monkopedia.ksrpc.sockets.asConnection
import com.monkopedia.ksrpc.sockets.withStdInOut
import com.monkopedia.ksrpc.toStub
import io.ktor.utils.io.ByteChannel
fun main() {
//sampleStart
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))
//sampleEnd
}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.
suspend fun Pair<InputStream, OutputStream>.asConnection(env: KsrpcEnvironment<String>): Connection<String>
Helper that calls into Pair
Create a Connection that starts the process and uses the Process.getInputStream and Process.getOutputStream as the streams for communication