Grpc-从一个客户端向连接到同一服务器的另一个客户端发送消息 [英] Grpc - send message from one client to another client that is connected to the same server

查看:122
本文介绍了Grpc-从一个客户端向连接到同一服务器的另一个客户端发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将消息从一个客户端发送到连接到同一服务器的另一个客户端?

Is it possible to send message from one client to another client that is connected to the same server?

我想将数据从一个客户端发送到服务器,然后发送到特定客户端.我想我需要获取客户端ID,但我不知道如何获取此ID以及如何从服务器向该客户端发送此消息.

I want send data from one client to server Then send to specific client. I think I need to get client ID but I dont know how to get this id and how to send this message to that client from server.

推荐答案

没有特殊的gRPC功能可以执行此操作(所有RPC都在服务器和客户端之间,没有广播"或选择性广播"功能可以连接到连接到同一服务器的其他客户端.

There's no special gRPC feature that would allow you to do this (all RPC are between a server and a client, there's no "broadcast" or "selective broadcast" feature to reach out to other clients connected to the same server.

您想要的逻辑肯定可以实现,但是这种解决方案的细节取决于您的需要.可能有效的幼稚方法是这个:

The logic you want is something that can definitely be implemented and but details of such solution depend on your need. A naive approach that might work is e.g. this:

  • 每个客户端向服务器打开一个双向出价调用
  • 服务器保留已连接客户端的目录
  • 一旦服务器接收到来自客户端的消息,它就会根据目录选择应转发给哪个客户端.
  • 服务器将邮件转发给客户端.

不用说,此设置感觉有点复杂(您基本上是在gRPC之上实现自己的网络协议),因此即使这可能是您正确的选择,但考虑一下还是有道理的如何简化协议,以便可以使用gRPC直接支持的功能.

Needless to say this setup feels a bit complicated (you're basically implementing your own network protocol on top of gRPC), so even though it might be just the right thing for you to do, it would make sense to think about how to simplify the protocol so that you can use features directly supported by gRPC.

这篇关于Grpc-从一个客户端向连接到同一服务器的另一个客户端发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆