...

/

Bidirectional Streaming RPC

Bidirectional Streaming RPC

Learn about a bidirectional streaming RPC in gRPC, and how to implement it.

Overview

Bidirectional streaming RPC is one of the four types of remote procedure call (RPC) in gRPC. In this type of RPC, both the client and server send a stream of messages to each other. This type of RPC is useful when both parties need to exchange a large amount of data continuously or interact in real-time.

In bidirectional streaming RPC, the client opens a channel to the server and both can send and receive messages independently. The client sends a stream of messages to the server, and the server sends a stream of messages in response to the client’s messages, allowing for full-duplex communication. This means that the client and server can read and write messages in parallel without waiting for the other party to finish.

Unlike blocking RPC, bidirectional streaming allows asynchronous communication, making it possible for both sides to process data as it becomes available. Bidirectional communication is ideal for applications requiring real-time updates or interactions, such as chat applications, live data feeds, or collaborative tools. Example use cases include chat applications, online gaming, collaborative editing, and stream data processing.

getFileAttributes RPC in FTP service

An example of a bidirectional streaming RPC in the FTP service is when the client requests file attributes from the server. The client can send multiple requests, and the server sends multiple responses.

We can define a getFileAttributes RPC in the ftp_service.proto file. The client opens a channel and sends a request to get the attributes of a file on the server. The client sends the name of the file in each request. When the getFileAttributes RPC is called, and the server expects a MetaData message containing the file name. The server checks if the file exists and then sends the file ...