0

I think I understand the client-server structure in gRPC, but don't know how to enable the server to call RPCs on the client. Do I implement both Client & Server (figure both server & stubs) on both sides and have 2 separate channels afterwards or is there a feature I missed?

  • Have you tried running the client/server examples? Here's the official Python [tutorial](https://grpc.github.io/docs/tutorials/basic/python.html) and their sets of [examples](https://github.com/grpc/grpc/tree/master/examples/python). You generally have one process for the server, and however many clients you want. The clients create a channel to the server, create a stub with the channel, and then call the RPC on the stub. – alkasm Jan 04 '21 at 20:07
  • Sorry, made a mistake in the question. Yes, I tried those and they behave as expected. However, I need the server to be able to call the clients. – mostermann Jan 04 '21 at 20:17
  • Can you give a little more explanation of what you want to do? It isn't clear if you want a client-streaming RPC or if you actually need a server on both ends. – alkasm Jan 04 '21 at 20:21
  • I'll probably have to use a server on both ends. If an event happens on the client, it calls the server for information about other clients. Simultaneously the other clients need to receive the updated information from the server about the original client. – mostermann Jan 04 '21 at 20:27
  • @mostermann if my answer helped you,you can accept it by clicking the gray checkmark next to it – new Q Open Wid Jan 04 '21 at 20:28
  • You might want to consider a pubsub system for events – alkasm Jan 04 '21 at 23:52

1 Answers1

1

No. A server cannot invoke a call on the client. Here is a quote from a question I found on SO: Can both ends of a gRPC connection accept method calls?

gRPC works with HTTP, and HTTP has not had such semantics in the past.

There has been discussion as to various ways to achieve such a feature, but I'm unaware of any work having started or general agreement on a design. gRPC does support bidirectional streaming, which may get you some of what you need. With bidirectional streaming the client can respond to messages from server, but the client still calls the server and only one type of message can be sent for that call.

new Q Open Wid
  • 2,225
  • 2
  • 18
  • 34