private static async Task ServerStreamingAsync(TestService.TestServiceClient client) { var cts = new CancellationTokenSource(); cts.CancelAfter(TimeSpan.FromSeconds(4)); using var reply = client.SayHellos(new HelloRequest { Name = "mostafa laoy" }); try { while (await reply.ResponseStream.MoveNext()) { Console.WriteLine(reply.ResponseStream.Current.Message); } Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("End Server Stream"); } catch (RpcException ex) when(ex.StatusCode == StatusCode.Cancelled) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Stream cancelled."); } }