private void Echo_Req(ReceiveData data) { _counter.Add(1); Packet resPacket = new Packet(Protocol.Echo_Res); Send(data.Sender as EndPoint, resPacket); }
private void Echo_Res(Packet data) { _counter.Add(1); Packet reqPacket = new Packet(Protocol.Echo_Req); Send(reqPacket); }
protected override void OnAccept() { Logger.Write(LogType.Info, 2, "[{0}] Accepted", SessionId); // Hello packet을 클라이언트에 전달 Packet packet = new Packet(0x01); SendPacket(packet); }
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); }
private void OnAcceptd(IOEventResult result) { Logger.Info("[{0}] Accepted", SessionId); // Hello packet을 클라이언트에 전달 Packet packet = new Packet(Protocol.Hello_Ntf); SendPacket(packet); }
public void Send(EndPoint ep, Packet packet) { try { _udp.Send(ep, packet.Buffer); } catch (Exception e) { Logger.Err(e.ToString()); } }
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; } }); }
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(); }); }
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)); } ); }
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; } }); }
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()); } }
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); }); }
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; }
private void OnReceived(IOEventResult result) { Packet packet = new Packet(result.Buffer); Logger.Err("Invalid packet received(PacketId={0:X})", packet.PacketId); }
private void OnEcho_Req(Packet packet) { Packet resPacket = new Packet(0x03); SendPacket(resPacket); }
private void Hello_Ntf(Packet packet) { Packet reqPacket = new Packet(Protocol.Echo_Req); reqPacket.Write(_tempBuffer, 0, FormMain.BufferSize); SendPacket(reqPacket); }
private void OnHello(Packet packet) { Packet reqPacket = new Packet(0x02); reqPacket.Write(_tempBuffer, 0, FormMain.BufferSize); SendPacket(reqPacket); }
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); } }
/// <summary> /// 이 SecurePacket 객체와 동일한 내용의 새로운 객체를 생성합니다. /// </summary> /// <returns>현재 SecurePacket의 데이터가 복제된 객체</returns> public override StreamBuffer Clone() { Packet packet = new Packet(this); packet.Read(ReadBytes); return packet; }
public ReceiveData(EndPoint sender, Packet packet) { Sender = sender; Packet = packet; }
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; }
private void Echo_Req(Packet packet) { Packet resPacket = new Packet(Protocol.Echo_Res); SendPacket(resPacket); }
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; }