Exemple #1
0
        private void ClientAppTest()
        {
            Debug.DefaultDebugger = new Server.ServerConsoleDebugger();

            MessageProcessor.DefaultSerializer = new Server.Serializer.MsgPackBitSerializer();

            var messageProcessor = new MessageProcessor();

            if (SynchronizationContext.Current == null)
            {
                SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            }
            messageProcessor.Run(TaskScheduler.FromCurrentSynchronizationContext());

            UdpClient udpClient = new UdpClient();

            udpClient.Run(IPAddress.Parse("192.168.0.128"), 8063);
            udpClient.OnRecvKcpPackage += messageProcessor.ProcessBytePackage;

            Task.Run(async() => {
                int count = 0;
                await Task.Delay(1000);
                Assert.False(udpClient.ConectionId == 0);
                var conv = udpClient.ConectionId.ToString();
                while (count++ < 10000)
                {
                    await Task.Delay(33);
                    var msg = new LoginReqMsg {
                        Account   = conv,
                        Password  = "******",
                        Extra     = count.ToString(),
                        SeqNumber = count,
                    };
                    udpClient.SendMessage(msg);
                    udpClient.SendMessage(msg);
                    udpClient.SendMessage(msg);
                }
                await Task.Delay(600 * 1000);
                udpClient.Stop();
                messageProcessor.Stop();
            });
        }
Exemple #2
0
        public void Init()
        {
            Debug.DefaultDebugger = new UnityConsoleDebugger();
            MessageProcessor.DefaultSerializer = new MsgPackBitSerializer();

            _messageProcessor = new MessageProcessor();
            TaskScheduler taskScheduler;

            if (SynchronizationContext.Current == null)
            {
                taskScheduler = TaskScheduler.Current;
            }
            else
            {
                taskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
            }
            _messageProcessor.Run(taskScheduler);

            UdpClient = new UdpClient();
            UdpClient.Run(IPAddress.Parse("192.168.0.116"), 8063);
            UdpClient.OnRecvKcpPackage += _messageProcessor.ProcessBytePackage;

            Status = AppStatus.Running;
        }