Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
jacking75 committed Dec 8, 2021
1 parent 3ada089 commit 06490ab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 59 deletions.
1 change: 1 addition & 0 deletions Tutorials/EchoServer/EchoServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<ItemGroup>
<Compile Remove="DevLog.cs" />
<Compile Remove="PacketHandlers.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
37 changes: 18 additions & 19 deletions Tutorials/EchoServer/MainServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class MainServer : AppServer<NetworkSession, EFBinaryRequestInfo>
{
public static SuperSocket.SocketBase.Logging.ILog MainLogger;

Dictionary<int, Action<NetworkSession, EFBinaryRequestInfo>> HandlerMap = new Dictionary<int, Action<NetworkSession, EFBinaryRequestInfo>>();
CommonHandler CommonHan = new CommonHandler();
//Dictionary<int, Action<NetworkSession, EFBinaryRequestInfo>> HandlerMap = new Dictionary<int, Action<NetworkSession, EFBinaryRequestInfo>>();
//CommonHandler CommonHan = new CommonHandler();

IServerConfig m_Config;

Expand All @@ -38,7 +38,7 @@ public MainServer()

void RegistHandler()
{
HandlerMap.Add((int)PACKETID.REQ_ECHO, CommonHan.RequestEcho);
//HandlerMap.Add((int)PACKETID.REQ_ECHO, CommonHan.RequestEcho);

MainLogger.Info("핸들러 등록 완료");
}
Expand Down Expand Up @@ -74,7 +74,7 @@ public void CreateServer()
CounterTh = new Thread(EchoCounter);
CounterTh.Start();

MainLogger.Info("서버 생성 성공");
MainLogger.Info($"[{DateTime.Now}] 서버 생성 성공");
}
catch(Exception ex)
{
Expand All @@ -90,7 +90,7 @@ void EchoCounter()
Thread.Sleep(1000);

var value = Interlocked.Exchange(ref Count, 0);
Console.WriteLine($"{DateTime.Now} : {value}");
//Console.WriteLine($"{DateTime.Now} : {value}");
}
}

Expand All @@ -106,34 +106,33 @@ public bool IsRunning(ServerState eCurState)

void OnConnected(NetworkSession session)
{
//MainLogger.Info($"세션 번호 {session.SessionID} 접속 start, ThreadId: {System.Threading.Thread.CurrentThread.ManagedThreadId}");
MainLogger.Debug($"[{DateTime.Now}] 세션 번호 {session.SessionID} 접속 start, ThreadId: {System.Threading.Thread.CurrentThread.ManagedThreadId}");

//Thread.Sleep(3000);
//MainLogger.Info($"세션 번호 {session.SessionID} 접속 end, ThreadId: {System.Threading.Thread.CurrentThread.ManagedThreadId}");
}

void OnClosed(NetworkSession session, CloseReason reason)
{
//MainLogger.Info($"세션 번호 {session.SessionID}, 접속해제: {reason.ToString()}");
MainLogger.Info($"[{DateTime.Now}] 세션 번호 {session.SessionID}, 접속해제: {reason.ToString()}");
}

void RequestReceived(NetworkSession session, EFBinaryRequestInfo reqInfo)
{
//MainLogger.Debug($"세션 번호 {session.SessionID}, 받은 데이터 크기: {reqInfo.Body.Length}, ThreadId: {System.Threading.Thread.CurrentThread.ManagedThreadId}");
MainLogger.Debug($"[{DateTime.Now}] 세션 번호 {session.SessionID}, 받은 데이터 크기: {reqInfo.Body.Length}, ThreadId: {System.Threading.Thread.CurrentThread.ManagedThreadId}");

Interlocked.Increment(ref Count);

session.Send(reqInfo.Body);
/*var PacketID = reqInfo.PacketID;


if (HandlerMap.ContainsKey(PacketID))
{
HandlerMap[PacketID](session, reqInfo);
}
else
{
MainLogger.Info($"세션 번호 {session.SessionID} 받은 데이터 크기: {reqInfo.Body.Length}");
}*/
var totalSize = (Int16)(reqInfo.Body.Length + EFBinaryRequestInfo.HEADERE_SIZE);

List<byte> dataSource = new List<byte>();
dataSource.AddRange(BitConverter.GetBytes(totalSize));
dataSource.AddRange(BitConverter.GetBytes((Int16)reqInfo.PacketID));
dataSource.AddRange(new byte[1]);
dataSource.AddRange(reqInfo.Body);

session.Send(dataSource.ToArray(), 0, dataSource.Count);
}
}

Expand Down
40 changes: 0 additions & 40 deletions Tutorials/EchoServer/PacketHandlers.cs

This file was deleted.

0 comments on commit 06490ab

Please sign in to comment.