Пример #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);
                    }
        }
Пример #2
0
        static void RunThriftBio()
        {
            //TTransport transport = new TSocket("localhost", 7911);
            //TProtocol protocol = new TBinaryProtocol(transport);
            //Helloword.Client client = new Helloword.Client(protocol);
            //transport.Open();
            //String user = "******";
            //CodeTimerAdvance.TimeByConsole("thrift bio", _count, a =>
            //{
            //    var reply = client.SayHello(new HelloRequest { Name = user });
            //}, _threadcount);
            //transport.Close();


            //多线程不能复用TSocket故需每次实例化。
            String user = "******";

            CodeTimerAdvance.TimeByConsole("thrift bio", _count, a =>
            {
                TTransport transport = new TSocket("localhost", 7911);
                transport.Open();
                TProtocol protocol = new TBinaryProtocol(transport);
                using (Helloword.Client client = new Helloword.Client(protocol))
                {
                    var reply = client.SayHello(new HelloRequest {
                        Name = user
                    });
                }
                transport.Close();
            }, _threadcount);
        }