1
votes

I have a question about gRPC communication.

I know gRPC has 4 models communication: unay, server-streaming, client-streaming and bi-direction. And the terms "client" and "server" very flexible, because it really is peer-to-peer communication.

I wonder "Can gRPC supports client-to-client communcation in case two or many clients locate in different LAN network"? Like image bellow: enter image description here

For example, in MQTT protocol, two clients locate in different LAN network can communicate through topic in MQTT broker.

If pure gRPC can't support this model, can I add other ingredient to make gRPC support this communication?

1
While gRPC supports bi-directional communication there is still a client (initiates connection) and a server (accepts connection). The connection is HTTP/2 which runs over TCP so, in most situations, the client needs to be able to establish a TCP connection with the server (however this can be proxied at the TCP or HTTP/2 level).Brits

1 Answers

1
votes

What you have diagramed should work perfectly fine. Both clients connect to the same server with a bidirectional stream, and the server forwards messages from CLIENT(1) intended for CLIENT(2) and vice-versa.

This would be for the simple case. If you needed to add fault tolerance (e.g. multiple servers), you would need more complexity in the system, like a database to store messages that have not yet been received.

Note that your comparison is not quite valid as MQTT is at the application layer of the stack, while gRPC is a part of the transport layer. (Note the table on the right of https://en.wikipedia.org/wiki/MQTT.)