January 2020
Intermediate to advanced
640 pages
16h 56m
English
In a server-streaming RPC scenario, the client initiates an RPC on the server and receives a stream of responses. Clients block reading on the stream until new data becomes available or the server closes the stream. In the latter case, the client read request will return an io.EOF error to indicate that no more data is available.
In the following example, we are defining a service that streams price updates for a particular cryptocurrency:
message CryptoPriceRequest { string crypto_type = 1;}message CryptoPrice { double price = 1;}service PriceService { rpc StreamCryptoPrice (CryptoPriceRequest) returns (stream CryptoPrice);}The following code shows the server-side implementation for the StreamCryptoPrice RPC:
var ...