Пример #1
0
        public override Task <SayHelloResultArgs> SayHello(SayHelloArgs args, ServerCallContext context)
        {
            //Console.WriteLine(args.Name + Count++);

            return(Task.FromResult(new SayHelloResultArgs {
                Message = $"Hello {args.Name}"
            }));
        }
Пример #2
0
        /// <summary>
        /// Grpc
        /// </summary>
        /// <remark>
        /// 1、Google
        /// 2、跨平台(原生)
        /// 3、基于Http2设计,支持双向流、消息头压缩、单 TCP 的多路复用、服务端推送等特性,在移动端设备上更加省电和节省网络流量
        /// 4、VS2019原生支持,不需要脚本生成代理类
        /// </remark>
        static void Grpc()
        {
            Channel channel = new Channel($"{ServerIp}:{CommonHelper.GrpcPort}", ChannelCredentials.Insecure);
            var     client  = new Helloworld.HelloworldClient(channel);
            var     args    = new GrpcTest.SayHelloArgs {
                Name = TestVal
            };
            var length = args.CalculateSize();

            CodeTimerPro.Start("Grpc", Times, p =>
            {
                var result = client.SayHelloAsync(args);
            }, ThreadCount);

            channel.ShutdownAsync().Wait();
        }