fix : 더미클라 시간계산 버그 수정
This commit is contained in:
@@ -23,21 +23,25 @@ public class DummyClients
|
|||||||
set;
|
set;
|
||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ReceivedCount
|
public int ReceivedCount
|
||||||
{
|
{
|
||||||
set;
|
set;
|
||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double LastRttMs
|
public double LastRttMs
|
||||||
{
|
{
|
||||||
set;
|
set;
|
||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double TotalRttMs
|
public double TotalRttMs
|
||||||
{
|
{
|
||||||
set;
|
set;
|
||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int RttCount
|
public int RttCount
|
||||||
{
|
{
|
||||||
set;
|
set;
|
||||||
@@ -48,7 +52,7 @@ public class DummyClients
|
|||||||
{
|
{
|
||||||
this.clientId = clientId;
|
this.clientId = clientId;
|
||||||
listener = new EventBasedNetListener();
|
listener = new EventBasedNetListener();
|
||||||
manager = new NetManager(listener);
|
manager = new NetManager(listener);
|
||||||
|
|
||||||
listener.PeerConnectedEvent += netPeer =>
|
listener.PeerConnectedEvent += netPeer =>
|
||||||
{
|
{
|
||||||
@@ -58,13 +62,16 @@ public class DummyClients
|
|||||||
|
|
||||||
listener.NetworkReceiveEvent += (peer, reader, channel, deliveryMethod) =>
|
listener.NetworkReceiveEvent += (peer, reader, channel, deliveryMethod) =>
|
||||||
{
|
{
|
||||||
|
short code = reader.GetShort();
|
||||||
|
short bodyLength = reader.GetShort();
|
||||||
string? msg = reader.GetString();
|
string? msg = reader.GetString();
|
||||||
|
|
||||||
string[] parts = msg.Split(':');
|
if (msg != null && msg.StartsWith("Echo seq:") &&
|
||||||
if (parts.Length == 3 && parts[0] == "ack" && parts[1] == "seq" && int.TryParse(parts[2], out int seq) && pendingPings.TryGetValue(seq, out long sentTick))
|
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;
|
double rttMs = (Stopwatch.GetTimestamp() - sentTick) * 1000.0 / Stopwatch.Frequency;
|
||||||
LastRttMs = rttMs;
|
LastRttMs = rttMs;
|
||||||
TotalRttMs += rttMs;
|
TotalRttMs += rttMs;
|
||||||
RttCount++;
|
RttCount++;
|
||||||
pendingPings.Remove(seq);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -128,7 +128,7 @@ public abstract class ServerBase : INetEventListener
|
|||||||
// 0이라면 에코 서버 테스트용 따로 처리
|
// 0이라면 에코 서버 테스트용 따로 처리
|
||||||
if (type == 0)
|
if (type == 0)
|
||||||
{
|
{
|
||||||
HandleEcho(peer, payload);
|
HandleEcho(peer, data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,6 +190,8 @@ public abstract class ServerBase : INetEventListener
|
|||||||
|
|
||||||
// 세션에 넣지는 않는다.
|
// 세션에 넣지는 않는다.
|
||||||
NetDataReader reader = new NetDataReader(payload);
|
NetDataReader reader = new NetDataReader(payload);
|
||||||
|
short code = reader.GetShort();
|
||||||
|
short bodyLength = reader.GetShort();
|
||||||
Log.Debug("[Echo] : addr={Addr}, str={Str}", peer.Address, reader.GetString());
|
Log.Debug("[Echo] : addr={Addr}, str={Str}", peer.Address, reader.GetString());
|
||||||
SendTo(peer, payload);
|
SendTo(peer, payload);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user