Beispiel #1
0
        private static async Task StreamingAddAsync(Adder.AdderClient client)
        {
            using var call = client.Add();
            while (true)
            {
                var inputLine = Console.ReadLine();
                if (string.IsNullOrEmpty(inputLine))
                {
                    await call.RequestStream.CompleteAsync();

                    break;
                }
                if (int.TryParse(inputLine, out var parsedInput))
                {
                    await call.RequestStream.WriteAsync(new AddRequest { Value = parsedInput });
                }
                else
                {
                    throw new ArgumentException();
                }
            }
            var response = await call;

            Console.WriteLine($"Sum:\t{response.Sum}");
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var number = new Random().NextDouble() - 1.0;

            var channel = new GoogleGrpc.Core.Channel("localhost:50000", GoogleGrpc.Core.ChannelCredentials.Insecure);
            var client  = new Adder.AdderClient(channel);

            var numberNew = client.AddSimple(new Number {
                Value = number
            }).Value;

            channel.ShutdownAsync().Wait();

            Console.WriteLine($"Sent:      {number}");
            Console.WriteLine($"Returned:  {numberNew}");
        }