kotlinx.rpc 0.9.1 Help

Client

KrpcClient

KrpcClient is an abstract class that implements RpcClient and kRPC protocol logic.

Initialization

The client comes in two forms:

  • KrpcClient

  • InitializedKrpcClient

The only difference between them is that KrpcClient allows to delay the initialization of the transport until the first RPC request is sent. InitializedKrpcClient is initialized right away with a ready KrpcTransport instance.

Transport

The only thing required to be implemented is the transporting of the raw data. Abstract transport is represented by KrpcTransport interface.

To implement your own KrpcTransport you need to be able to transfer strings and/or raw bytes (Kotlin's ByteArray). Additionally, the library will provide you with integrations with different libraries that are used to work with the network.

See below an example usage of kRPC with a custom transport:

class MySimpleRpcTransport : KrpcTransport { val outChannel = Channel<KrpcTransportMessage>() val inChannel = Channel<KrpcTransportMessage>() override val coroutineContext: CoroutineContext = Job() override suspend fun send(message: KrpcTransportMessage) { outChannel.send(message) } override suspend fun receive(): KrpcTransportMessage { return inChannel.receive() } } class MySimpleRpcClient : KrpcClient(rpcClientConfig(), MySimpleRpcTransport()) val client = MySimpleRpcClient() val service: MyService = client.withService<MyService>()
Last modified: 13 June 2025