Skip to content

Can Server call Client defined Service? #403

@Krosxx

Description

@Krosxx

Is your feature request related to a problem? Please describe.
Can KtorRpcClient registerService, KrpcRoute withService, i.e. Server call Client defined Service?

Describe the solution you'd like

In KrpcClient:

    val rpcClient = client.rpc {
        url("ws://localhost:8080/rpc")
        rpcConfig { serialization { json() } }
    }
    rpcClient.registerService<ClientService> { ClientServiceImpl() }

In KrpcServer:

    routing {
        rpc("/rpc") {
            rpcConfig { serialization { json() } }
            // 获取客户端注册的 Service
            val clientService = withService<ClientService>()
            // 服务器调用客户端的 Service 方法
            val response = clientService.notify("Hello from server!")
            println("Client responded: $response")
        }
     }

Metadata

Metadata

Assignees

Labels

featureNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions