RPC Servers

Edit pageLast modified: 22 November 2024

RpcServer interface represents an RPC server, that accepts RPC messages and may contain multiple services to route to. RpcServer uses data from incoming RPC messages and routes it to the designated service and sends service's response back to the corresponding client.

You can provide your own RpcServer implementation or use the one provided out of the box. Note that client and server must use the same RPC protocol to communicate.

Use registerService function to add your own factory for implemented RPC services. This factory function should accept CoroutineContext argument and pass it to the service, which should use it to override coroutineContext property of parent interface. This ensures proper application lifetime for your services.

Example usage:

The registerService function requires the explicit type of the declared RPC service. That means that the code will not work if you provide it with the type of the service implementation: