Example #1
0
        /// <summary>测试主函数</summary>
        public async static void Main()
        {
            var svr = new ApiServer(3344);

            svr.Add("http://*:888/");
            svr.Log = XTrace.Log;
            svr.Register <HelloController>();
            svr.Encoder = new JsonEncoder();
            //svr.Encoder = new ProtocolBuffer();
            svr.Start();


            var client = new ApiClient("udp://127.0.0.1:3344");

            client.Log     = XTrace.Log;
            client.Encoder = new JsonEncoder();
            //client.Encoder = new ProtocolBuffer();
            //client.Compress = new SevenZip();
            client.Open();
            client.Login("admin", "password");

            var msg = "NewLifeX";
            var rs  = await client.Invoke <String>("Hello/SayHello", new { msg });

            Console.WriteLine(rs);

            Console.ReadKey();

            client.Dispose();
            svr.Dispose();
        }
Example #2
0
        /// <summary>测试主函数</summary>
        public static async void Main()
        {
            var svr = new ApiServer(3344);

            //svr.Add("http://*:888/");
            svr.Log     = XTrace.Log;
            svr.Encoder = new JsonEncoder();
            svr.Filters.Add(new DeflateFilter());
            svr.Filters.Add(new RC4Filter {
                Key = "Pass$word".GetBytes()
            });
            //GlobalFilters.Add(new FFAttribute { Name = "全局" });
            //GlobalFilters.Add(new FEAttribute { Name = "全局" });
            svr.Register <HelloController>();
            svr.Register(typeof(ApiTest), nameof(Login));
            svr.Start();


            var client = new ApiClient("tcp://127.0.0.1:3344");

            //var client = new ApiClient("udp://127.0.0.1:3344");
            //var client = new ApiClient("http://127.0.0.1:888");
            client.Log     = XTrace.Log;
            client.Encoder = new JsonEncoder();
            client.Filters.Add(new DeflateFilter());
            client.Filters.Add(new RC4Filter {
                Key = "Pass$word".GetBytes()
            });
            client.Open();

            var logined = await client.InvokeAsync <Object>("Login", new { user = "******", pass = "******" });

            XTrace.WriteLine(logined + "");

            var msg = "NewLifeX";
            var rs  = await client.InvokeAsync <string>("Hello/Say", new { msg });

            XTrace.WriteLine(rs);

            try
            {
                msg = "报错";
                rs  = await client.InvokeAsync <string>("Hello/Say", new { msg });
            }
            catch (ApiException ex)
            {
                XTrace.WriteLine("服务端发生 {0} 错误:{1}", ex.Code, ex.Message);
            }

            var apis = await client.InvokeAsync <String[]>("Api/All");

            Console.WriteLine(apis.Join(Environment.NewLine));

            Console.WriteLine("完成");
            Console.ReadKey();

            client.Dispose();
            svr.Dispose();
        }
Example #3
0
        /// <summary>开始会话处理</summary>
        public override void Start()
        {
            base.Start();

            _Host = Host.Host as ApiServer;

            //if (_Host is ApiHost host) host.OnNewSession(this, null);
        }
Example #4
0
        private static void TestServer()
        {
            var svr = new ApiServer(3344)
            {
                Log        = XTrace.Log,
                EncoderLog = XTrace.Log
            };

            svr.Register <HelloController>();

            //var ns = svr.Server as NetServer;
            //ns.LogSend = true;
            //ns.LogReceive = true;

            svr.Start();

            Console.ReadKey();
        }
Example #5
0
        private static void TestServer()
        {
            var svr = new ApiServer(3344);

            svr.Add("http://*:888/");
            svr.Log        = XTrace.Log;
            svr.EncoderLog = XTrace.Log;
            //svr.Encoder = new JsonEncoder();
            //GlobalFilters.Add(new FFAttribute { Name = "全局" });
            //GlobalFilters.Add(new FEAttribute { Name = "全局" });
            svr.Register <ApiSession>();
            svr.Register <HelloController>();

            var ns = svr.Servers[0] as NetServer;

            ns.LogSend    = true;
            ns.LogReceive = true;

            svr.Start();

            Console.ReadKey();
        }
Example #6
0
        /// <summary>开始会话处理</summary>
        public override void Start()
        {
            _Host = Host.Host as ApiServer;

            base.Start();
        }
Example #7
0
 public ApiManager(ApiServer server) => _server = server;