How to broadcast in gRPC from server to client?

前端 未结 3 739
野的像风
野的像风 2021-01-06 03:26

I\'m creating a small chat application in gRPC right now and I\'ve run into the issue where if a user wants to connect to the gRPC server as a client, I\'d like to broadcast

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-06 03:31

    Another approach is to spawn a grpc-server on client side too. On app-level you have some handshake from client to server to exchange the clients grpc-server ip and port. You probably want to create a client for that address at this point and store the client in a list.

    Now you can push messages to the clients from the list with default unary RPC calls. No [bidi] stream needed. Pros:

    • Possible to separate the clients "Push"-API from the server API.
    • Unary RPC push calls.

    Cons:

    • Additional "server". Don't know if that is possible in every scenario.

提交回复
热议问题