RPC Servers
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:
KRPCServer — RPCServer for kRPC Protocol
KRPCServer
abstract class implements RPCServer
and all the logic for processing RPC messages and again leaves RPCTransport
methods for the specific implementations (see transports).
Example usage with custom transport:
Note that here we pass explicit MyService
type parameter to the registerService
method. You must explicitly specify the type of the service interface here, otherwise the server service will not be found.