Exemplo n.º 1
0
        /// <summary>
        /// Facebook => Apace
        /// 跨平台
        /// 缺点:无法生成async,await,Task<T>之类的泛型代码
        ///
        /// Bug
        /// </summary>
        static void Thrift()
        {
            //CodeTimerPro.Start("Thrift", Times, _ =>
            //{
            //    using (TTransport transport = new TSocket(ServerIp, CommonHelper.ThriftPort))
            //    {
            //        using (TProtocol protocol = new TBinaryProtocol(transport))
            //        {
            //            using (Helloword.Client client = new Helloword.Client(protocol))
            //            {
            //                transport.Open();
            //                var result = client.SayHello(new SayHelloArgs { Name = "philia" });
            //            }
            //        }
            //    }
            //}, ThreadCount);


            using (TTransport transport = new TSocket(ServerIp, CommonHelper.ThriftPort))
                using (TProtocol protocol = new TBinaryProtocol(transport))
                    using (var client = new Helloword.Client(protocol))
                    {
                        transport.Open();
                        CodeTimerPro.Start("Thrift", Times, _ =>
                        {
                            var result = client.SayHello(new SayHelloArgs {
                                Name = TestVal
                            });
                        }, ThreadCount);
                    }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 微软
 ///
 /// 需要封装
 /// </summary>
 static void DotNettyTest()
 {
     DotNettyTest.IHello client = RPCClientFactory.GetClient <DotNettyTest.IHello>(ServerIp, CommonHelper.DotNettyPort);
     CodeTimerPro.Start("DotNetty", Times, _ =>
     {
         var result = client.SayHello(CommonArgs);
     }, ThreadCount);
 }
Exemplo n.º 3
0
        static void HttpClient()
        {
            var client      = new HttpClient();
            var buffer      = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(CommonArgs));
            var byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            CodeTimerPro.Start("HttpClient", Times, _ =>
            {
                var response = client.PostAsync($"http://{ServerIp}:{CommonHelper.WebApiPort}/api/Values", byteContent);
                var result   = response.Result.Content.ReadAsStringAsync().Result;
            }, ThreadCount);
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
        private static async Task <int> RunMainAsync()
        {
            using (var client = await OrleansClient())
            {
                var friend = client.GetGrain <HelloWorld.Interfaces.IHello>(0);
                CodeTimerPro.Start("Orleans", Times, async _ =>
                {
                    var result = await friend.SayHello(CommonArgs);
                    //Console.WriteLine(result.Message);
                }, ThreadCount);

                Console.ReadKey();
            }

            return(1);
        }
Exemplo n.º 6
0
        static void HttpWebRequest()
        {
            string url = $"http://{ServerIp}:{CommonHelper.WebApiPort}/api/Values";

            CodeTimerPro.Start("HttpWebRequest", Times, _ =>
            {
                HttpWebRequest webRequest  = (HttpWebRequest)WebRequest.Create(new Uri(url));
                webRequest.Method          = "post";
                webRequest.ContentType     = "application/application/json";
                string postData            = "Name=philia";
                byte[] byteArray           = Encoding.UTF8.GetBytes(postData);
                webRequest.ContentLength   = byteArray.Length;
                System.IO.Stream newStream = webRequest.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length);
                newStream.Close();
                HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
                string result            = new System.IO.StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
            }, ThreadCount);
        }