fix : 더미클라 시간계산 버그 수정

This commit is contained in:
qornwh1
2026-03-02 16:15:05 +09:00
parent 5dc944d644
commit 8fcdd3494e
3 changed files with 67 additions and 5 deletions

View File

@@ -23,21 +23,25 @@ public class DummyClients
set;
get;
}
public int ReceivedCount
{
set;
get;
}
public double LastRttMs
{
set;
get;
}
public double TotalRttMs
{
set;
get;
}
public int RttCount
{
set;
@@ -48,7 +52,7 @@ public class DummyClients
{
this.clientId = clientId;
listener = new EventBasedNetListener();
manager = new NetManager(listener);
manager = new NetManager(listener);
listener.PeerConnectedEvent += netPeer =>
{
@@ -58,13 +62,16 @@ public class DummyClients
listener.NetworkReceiveEvent += (peer, reader, channel, deliveryMethod) =>
{
short code = reader.GetShort();
short bodyLength = reader.GetShort();
string? msg = reader.GetString();
string[] parts = msg.Split(':');
if (parts.Length == 3 && parts[0] == "ack" && parts[1] == "seq" && int.TryParse(parts[2], out int seq) && pendingPings.TryGetValue(seq, out long sentTick))
if (msg != null && msg.StartsWith("Echo seq:") &&
int.TryParse(msg.Substring("Echo seq:".Length), out int seq) &&
pendingPings.TryGetValue(seq, out long sentTick))
{
double rttMs = (Stopwatch.GetTimestamp() - sentTick) * 1000.0 / Stopwatch.Frequency;
LastRttMs = rttMs;
LastRttMs = rttMs;
TotalRttMs += rttMs;
RttCount++;
pendingPings.Remove(seq);

View File

@@ -0,0 +1,53 @@
using ProtoBuf;
using Serilog;
namespace ClientTester.Packet
{
// 패킷 헤더 크기 4(패킷 타입, 패킷 길이)
public static class PacketSerializer
{
// 직렬화: 객체 → byte[]
public static byte[] Serialize<T>(ushort type, ushort size, T packet)
{
MemoryStream ms = new MemoryStream();
// 2바이트 패킷 타입 헤더
ms.WriteByte((byte)(type & 0xFF));
ms.WriteByte((byte)(type >> 8));
// 2바이트 패킷 길이 헤더
ms.WriteByte((byte)(size & 0xFF));
ms.WriteByte((byte)(size >> 8));
// protobuf 페이로드
Serializer.Serialize(ms, packet);
return ms.ToArray();
}
// 역직렬화: byte[] → (PacketType, payload bytes)
public static (ushort type, ushort size, byte[] payload) Deserialize(byte[] data)
{
if (data.Length < 4)
{
Log.Warning("[PacketHeader]의 길이가 4이하입니다.");
return (0, 0, null)!;
}
// 길이체크도 필요함
ushort type = (ushort)(data[0] | (data[1] << 8));
ushort size = (ushort)(data[2] | (data[3] << 8));
byte[] payload = new byte[data.Length - 4];
Buffer.BlockCopy(data, 4, payload, 0, payload.Length);
return (type, size, payload);
}
// 페이로드 → 특정 타입으로 역직렬화
public static T DeserializePayload<T>(byte[] payload)
{
MemoryStream ms = new MemoryStream(payload);
return Serializer.Deserialize<T>(ms);
}
}
}

View File

@@ -128,7 +128,7 @@ public abstract class ServerBase : INetEventListener
// 0이라면 에코 서버 테스트용 따로 처리
if (type == 0)
{
HandleEcho(peer, payload);
HandleEcho(peer, data);
return;
}
@@ -190,6 +190,8 @@ public abstract class ServerBase : INetEventListener
// 세션에 넣지는 않는다.
NetDataReader reader = new NetDataReader(payload);
short code = reader.GetShort();
short bodyLength = reader.GetShort();
Log.Debug("[Echo] : addr={Addr}, str={Str}", peer.Address, reader.GetString());
SendTo(peer, payload);
}