Beispiel #1
0
        public void TestMethod1()
        {
            Login2Gate login2Gate = new Login2Gate()
            {
                Account  = "test",
                Password = "******"
            };

            {
                var b   = MessagePack.MessagePackSerializer.Serialize(login2Gate);
                var res = MessagePack.MessagePackSerializer.Deserialize <Login2Gate>(b);
                Assert.AreEqual(login2Gate.Account, res.Account);
                Assert.AreEqual(login2Gate.Password, res.Password);
            }

            {
                using (MemoryStream ms = new MemoryStream(1024))
                {
                    Serializer.Serialize(ms, login2Gate);
                    ms.Seek(0, SeekOrigin.Begin);
                    var res = Serializer.Deserialize <Login2Gate>(ms);
                    Assert.AreEqual(login2Gate.Account, res.Account);
                    Assert.AreEqual(login2Gate.Password, res.Password);
                }

                Protobuf_netLUT.Regist(typeof(Login2Gate).Assembly);
                using (var buffer = BufferPool.Rent(1024))
                {
                    var length = MessageLUT.Serialize(login2Gate, buffer.Memory.Span);
                    var res    = MessageLUT.Deserialize(1003, buffer.Memory.Slice(0, length.length)) as Login2Gate;
                    Assert.AreEqual(login2Gate.Account, res.Account);
                    Assert.AreEqual(login2Gate.Password, res.Password);
                }
            }
        }
Beispiel #2
0
        private static async void InitServer()
        {
            //MessagePackLUT.Regist(typeof(Login).Assembly);
            Protobuf_netLUT.Regist(typeof(Login).Assembly);
            ThreadPool.QueueUserWorkItem((A) =>
            {
                while (true)
                {
                    MessageThreadTransducer.Update(0);
                    Thread.Yield();
                }
            });

            await DCSContainer.Start();

            //FightService service = new FightService();
            //BusinessContainer.Instance.AddService(service);
            GateService gateService = new GateService();

            DCSContainer.AddService(gateService);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            //decimal.TryParse("               1.03", out var a);
            //HttpClient c = new HttpClient();
            //var str = "1212";
            //var data = new StringContent(str, System.Text.Encoding.UTF8);
            //var t = c.PostAsync("http://localhost:56727/api/boc/Save", data);
            //var s = t.Result.Content.ReadAsStringAsync().Result;


            //将协议类的程序集注册进查找表中
            Protobuf_netLUT.Regist(typeof(Login).Assembly);
            //    Protobuf_netLUT.Regist(typeof(Login).Assembly);

            //建立主线程 或指定的任何线程 轮询。(确保在unity中使用主线程轮询)
            //ThreadScheduler保证网络底层的各种回调函数切换到主线程执行以保证执行顺序。
            ThreadPool.QueueUserWorkItem((A) =>
            {
                while (true)
                {
                    MessageThreadTransducer.Update(0);
                    Thread.Yield();
                }
            });

            ConnectAsync();
            while (true)
            {
                var line = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(line))
                {
                    break;
                }
                remote.SendAsync(line);
            }
            Console.ReadLine();
        }