Size(2 bytes), PacketId(2 bytes)로 구성된 4바이트 헤더를 갖는 기본 패킷 구성입니다.
Inheritance: Aegis.IO.StreamBuffer
示例#1
0
        private void Echo_Req(ReceiveData data)
        {
            _counter.Add(1);

            Packet resPacket = new Packet(Protocol.Echo_Res);
            Send(data.Sender as EndPoint, resPacket);
        }
示例#2
0
        private void Echo_Res(Packet data)
        {
            _counter.Add(1);

            Packet reqPacket = new Packet(Protocol.Echo_Req);
            Send(reqPacket);
        }
示例#3
0
        protected override void OnAccept()
        {
            Logger.Write(LogType.Info, 2, "[{0}] Accepted", SessionId);

            //  Hello packet을 클라이언트에 전달
            Packet packet = new Packet(0x01);
            SendPacket(packet);
        }
示例#4
0
        private void OnReceived(IOEventResult result)
        {
            IntervalCounter.Counters["ReceiveCount"].Add(1);
            IntervalCounter.Counters["ReceiveBytes"].Add(result.Buffer.Length);

            Packet packet = new Packet(result.Buffer);
            Logger.Err("Invalid packet received(PacketId={0:X})", packet.PacketId);
        }
示例#5
0
        private void OnAcceptd(IOEventResult result)
        {
            Logger.Info("[{0}] Accepted", SessionId);

            //  Hello packet을 클라이언트에 전달
            Packet packet = new Packet(Protocol.Hello_Ntf);
            SendPacket(packet);
        }
示例#6
0
 public void Send(EndPoint ep, Packet packet)
 {
     try
     {
         _udp.Send(ep, packet.Buffer);
     }
     catch (Exception e)
     {
         Logger.Err(e.ToString());
     }
 }
示例#7
0
 protected override void OnReceive(StreamBuffer buffer)
 {
     Packet packet = new Packet(buffer);
     AegisTask.Run(() =>
     {
         packet.SkipHeader();
         switch (packet.PID)
         {
             case 0x01: OnHello(packet); break;
             case 0x03: OnEcho_Res(packet); break;
         }
     });
 }
示例#8
0
        public TestSession()
        {
            base.EventConnect += OnConnected;
            base.EventClose += OnClosed;
            base.EventReceive += OnReceived;
            base.PacketValidator += Packet.IsValidPacket;

            CreatePacketDispatcher(this, (ref StreamBuffer source, out string key) =>
            {
                source = new Packet(source as StreamBuffer);
                key = (source as Packet).PacketId.ToString();
                (source as Packet).SkipHeader();
            });
        }
示例#9
0
        private void Echo_Res(Packet packet)
        {
            Packet reqPacket = new Packet(Protocol.Echo_Req);
            reqPacket.Write(_tempBuffer, 0, FormMain.BufferSize);

            SendPacket(reqPacket,
                        (buffer) => { return Packet.GetPacketId(buffer.Buffer) == Protocol.Echo_Res; },
                        (result) =>
                        {
                            packet.SkipHeader();
                            Echo_Res(new Packet(result.Buffer));
                        }
                );
        }
示例#10
0
        protected override void OnReceive(StreamBuffer buffer)
        {
            Counter_ReceiveCount.Add(1);
            Counter_ReceiveBytes.Add(buffer.WrittenBytes);

            Packet packet = new Packet(buffer);
            AegisTask.Run(() =>
            {
                packet.SkipHeader();
                switch (packet.PID)
                {
                    case 0x02: OnEcho_Req(packet); break;
                }
            });
        }
示例#11
0
 private void NetworkEvent_Receive(IOEventResult result)
 {
     try
     {
         int packetSize;
         if (Packet.IsValidPacket(result.Buffer, 0, result.Buffer.Length, out packetSize) == true)
         {
             Packet packet = new Packet(result.Buffer);
             if (_packetDispatcher.Dispatch(new ReceiveData(result.Sender as EndPoint, packet)) == false)
                 Logger.Err("[GameProcess] Invalid packet received(pid=0x{0:X}).", packet.PacketId);
         }
     }
     catch (Exception e)
     {
         Logger.Err(e.ToString());
     }
 }
示例#12
0
        public ClientSession()
        {
            base.EventAccept += OnAcceptd;
            base.EventClose += OnClosed;
            base.EventReceive += OnReceived;
            base.PacketValidator += Packet.IsValidPacket;

            CreatePacketDispatcher(this, (ref StreamBuffer source, out string key) =>
            {
                source = new Packet(source as StreamBuffer);
                key = (source as Packet).PacketId.ToString();
                (source as Packet).SkipHeader();

                IntervalCounter.Counters["ReceiveCount"].Add(1);
                IntervalCounter.Counters["ReceiveBytes"].Add((source as Packet).Buffer.Length);
            });
        }
示例#13
0
        public Boolean ProcessResponseWaitPacket(Packet packet)
        {
            lock (_listTCS)
            {
                foreach (TCSData data in _listTCS)
                {
                    if (data.packetId == packet.PacketId
                        && (data.predicate == null || data.predicate(packet) == true))
                    {
                        data.tcs.SetResult(new Packet(packet));
                        _listTCS.Remove(data);

                        return true;
                    }
                }
            }

            return false;
        }
示例#14
0
 private void OnReceived(IOEventResult result)
 {
     Packet packet = new Packet(result.Buffer);
     Logger.Err("Invalid packet received(PacketId={0:X})", packet.PacketId);
 }
示例#15
0
 private void OnEcho_Req(Packet packet)
 {
     Packet resPacket = new Packet(0x03);
     SendPacket(resPacket);
 }
示例#16
0
 private void Hello_Ntf(Packet packet)
 {
     Packet reqPacket = new Packet(Protocol.Echo_Req);
     reqPacket.Write(_tempBuffer, 0, FormMain.BufferSize);
     SendPacket(reqPacket);
 }
示例#17
0
 private void OnHello(Packet packet)
 {
     Packet reqPacket = new Packet(0x02);
     reqPacket.Write(_tempBuffer, 0, FormMain.BufferSize);
     SendPacket(reqPacket);
 }
示例#18
0
        private void Start()
        {
            _packetDispatcher = new MethodSelector<Packet>(this, (ref Packet source, out string key) =>
            {
                key = source.PacketId.ToString();
                source.SkipHeader();
            });

            _udp = new UDPClient();
            _udp.EventRead += NetworkEvent_Receive;
            _udp.EventClose += NetworkEvent_Close;
            _udp.Connect("127.0.0.1", 10201);

            _counter = new IntervalCounter(1000);
            _counter.Start();
            (new IntervalTimer(1000, () =>
            {
                DateTime now = DateTime.Now;
                Console.WriteLine(string.Format("[{0}/{1} {2}:{3}:{4}] recv: {5}",
                                        DateTime.Now.Month, DateTime.Now.Day,
                                        DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second,
                                        _counter.Value));
            })).Start();

            {
                Packet reqPacket = new Packet(Protocol.Echo_Req);
                Send(reqPacket);
            }
        }
示例#19
0
        /// <summary>
        /// 이 SecurePacket 객체와 동일한 내용의 새로운 객체를 생성합니다.
        /// </summary>
        /// <returns>현재 SecurePacket의 데이터가 복제된 객체</returns>
        public override StreamBuffer Clone()
        {
            Packet packet = new Packet(this);
            packet.Read(ReadBytes);

            return packet;
        }
示例#20
0
 public ReceiveData(EndPoint sender, Packet packet)
 {
     Sender = sender;
     Packet = packet;
 }
示例#21
0
        public virtual async Task<Packet> SendAndWaitResponse(Packet packet, UInt16 responsePacketId, Func<Packet, Boolean> predicate, Int32 timeout)
        {
            TaskCompletionSource<Packet> tcs = new TaskCompletionSource<Packet>();
            CancellationTokenSource cancel = new CancellationTokenSource();
            TCSData data = new TCSData() { packetId = responsePacketId, tcs = tcs, predicate = predicate };
            Packet response = null;


            lock (_listTCS)
            {
                _listTCS.Add(data);
            }


            //  Task.Result의 Timeout 처리
            Task.Run(async () =>
            {
                try
                {
                    await Task.Delay(timeout, cancel.Token);
                    tcs.SetCanceled();
                }
                catch (Exception)
                {
                }
            });

            //  Packet Send & Response 작업
            await Task.Run(() =>
            {
                try
                {
                    _session.SendPacket(packet);
                    response = tcs.Task.Result;
                    cancel.Cancel();
                }
                catch (Exception)
                {
                    //  Task가 Cancel된 경우 추가된 작업(data)을 삭제한다.
                    _listTCS.Remove(data);
                }
            });

            cancel.Dispose();


            if (response == null)
                throw new WaitResponseTimeoutException("The waiting time of ResponsePacketId(0x{0:X}) has expired.", responsePacketId);

            return response;
        }
示例#22
0
 private void Echo_Req(Packet packet)
 {
     Packet resPacket = new Packet(Protocol.Echo_Res);
     SendPacket(resPacket);
 }
示例#23
0
        public virtual async Task<Packet> SendAndWaitResponse(Packet packet, UInt16 responsePacketId)
        {
            TaskCompletionSource<Packet> tcs = new TaskCompletionSource<Packet>();
            TCSData data = new TCSData() { packetId = responsePacketId, tcs = tcs, predicate = null };
            Packet response = null;


            lock (_listTCS)
            {
                _listTCS.Add(data);
            }


            await Task.Run(() =>
            {
                try
                {
                    _session.SendPacket(packet);
                    response = tcs.Task.Result;
                }
                catch (Exception)
                {
                    //  Nothing to do.
                }
            });

            return response;
        }