3 Commits

4 changed files with 33 additions and 21 deletions

View File

@@ -38,7 +38,7 @@ public class DummyClientService
try
{
await Task.Delay(15, ct);
await Task.Delay(10, ct);
}
catch (OperationCanceledException)
{
@@ -85,7 +85,7 @@ public class DummyClientService
break;
}
Log.Information("[TICK {Tick:000}] {Sent}/{Total} 전송", tick, sent, total);
Log.Debug("[TICK {Tick:000}] {Sent}/{Total} 전송", tick, sent, total);
tick++;
try

View File

@@ -1,3 +1,4 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using ClientTester.Packet;
using LiteNetLib;
@@ -8,13 +9,14 @@ namespace ClientTester.EchoDummyService;
public class DummyClients
{
public NetManager manager;
public EventBasedNetListener listener;
private NetManager manager;
private EventBasedNetListener listener;
private NetDataWriter? writer;
public NetPeer? peer;
public int clientId;
// seq → 송신 타임스탬프 (Stopwatch tick)
private readonly Dictionary<int, long> pendingPings = new();
private ConcurrentDictionary<int, long> pendingPings = new();
private int seqNumber;
// 통계
@@ -53,6 +55,7 @@ public class DummyClients
this.clientId = clientId;
listener = new EventBasedNetListener();
manager = new NetManager(listener);
writer = new NetDataWriter();
listener.PeerConnectedEvent += netPeer =>
{
@@ -65,16 +68,16 @@ public class DummyClients
short code = reader.GetShort();
short bodyLength = reader.GetShort();
string? msg = reader.GetString();
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))
pendingPings.TryRemove(seq, out sentTick))
{
double rttMs = (Stopwatch.GetTimestamp() - sentTick) * 1000.0 / Stopwatch.Frequency;
LastRttMs = rttMs;
TotalRttMs += rttMs;
RttCount++;
pendingPings.Remove(seq);
}
ReceivedCount++;
@@ -93,7 +96,7 @@ public class DummyClients
public void SendPing()
{
if (peer == null)
if (peer == null || writer == null)
{
return;
}
@@ -101,15 +104,16 @@ public class DummyClients
int seq = seqNumber++;
pendingPings[seq] = Stopwatch.GetTimestamp();
NetDataWriter writer = new NetDataWriter();
PacketHeader packetHeader = new PacketHeader();
packetHeader.Code = 0;
packetHeader.BodyLength = $"seq:{seq}".Length;
writer.Put((short)packetHeader.Code);
writer.Put((short)packetHeader.BodyLength);
writer.Put($"Echo seq:{seq}");
peer.Send(writer, DeliveryMethod.ReliableOrdered);
// 순서보장 안함 HOL Blocking 제거
peer.Send(writer, DeliveryMethod.ReliableUnordered);
SentCount++;
writer.Reset();
}
public double AvgRttMs => RttCount > 0 ? TotalRttMs / RttCount : 0.0;

View File

@@ -7,7 +7,7 @@ namespace MMOserver;
class Program
{
private static void Main()
private static async Task Main()
{
// .MinimumLevel.Warning() // Warning 이상만 출력 배포시
@@ -43,17 +43,24 @@ class Program
};
// 게임 서버 스레드 생성
Thread serverThread = new Thread(() =>
{
gameServer.Init();
gameServer.Run();
});
// Thread serverThread = new Thread(() =>
// {
// gameServer.Init();
// gameServer.Run();
// });
// 게임 서버 스레드 시작
serverThread.Start();
// serverThread.Start();
// Run()이 끝날 때까지 대기
serverThread.Join();
// serverThread.Join();
// 비동기 변경
await Task.Run(async () =>
{
gameServer.Init();
await gameServer.Run();
});
// Log 종료
Log.CloseAndFlush();

View File

@@ -61,7 +61,7 @@ public abstract class ServerBase : INetEventListener
isListening = true;
}
public virtual void Run()
public async Task Run()
{
netManager.Start(Port);
Log.Information("[Server] 시작 Port={Port}", Port);
@@ -69,7 +69,7 @@ public abstract class ServerBase : INetEventListener
while (isListening)
{
netManager.PollEvents();
Thread.Sleep(15);
await Task.Delay(1);
}
netManager.Stop();
Log.Information("[Server] 종료 Port={Port}", Port);
@@ -193,7 +193,8 @@ public abstract class ServerBase : INetEventListener
short code = reader.GetShort();
short bodyLength = reader.GetShort();
Log.Debug("[Echo] : addr={Addr}, str={Str}", peer.Address, reader.GetString());
SendTo(peer, payload);
// Echo메시지는 순서보장 안함 HOL Blocking 제거
SendTo(peer, payload, DeliveryMethod.ReliableUnordered);
}
// ─── Auth 처리 (내부) ────────────────────────────────────────────────