fix : 더미클라 시간계산 버그 수정
This commit is contained in:
@@ -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);
|
||||
|
||||
53
ClientTester/EchoClientTester/Packet/PacketSerializer.cs
Normal file
53
ClientTester/EchoClientTester/Packet/PacketSerializer.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user