Closed Jire closed 1 day ago
The protocol is not yet standardized for good. but at this time, I think the intended solution for server->client communication is flows.
Every instance of RemoteService
is tide to a websocket session. So, you could give each client connection a flow instance as a field in the remote service to subscribe to.
@Rpc
interface MyService : RemoteService {
val serverToClientRequests: Flow<MyServerRequest>
}
Also, you could return a flow as a result of a remote service function invocation.
@Rpc
interface MyService : RemoteService {
fun subscribeToServerRequests(): Flow<MyServerRequest>
}
Sorry for weak answer. I am only a user not a contributor
In documentation, there is no example shown of how to send a request from server -> client over an RPC call, only client -> server.
I am not sure if this is just a missing feature, or just missing documentation, but I find this a critical feature for my application, and would like to see the "right way to do it".
I have implemented an interval-polled subscribe system which I use to accomplish this, but if there's a "right way" to do this, that would be preferred.
Something maybe like this:
Here is a stripped-down version of my implementation to achieve something similar, although with the drawback that it only polls at a set interval and thus has polling overhead + delay:
API module (client and server both depend on this code):
Server module:
Then a client can utilize it like this: