diff --git a/Tutorials/EchoServer/EchoServer.csproj b/Tutorials/EchoServer/EchoServer.csproj index b214894..7a973ed 100644 --- a/Tutorials/EchoServer/EchoServer.csproj +++ b/Tutorials/EchoServer/EchoServer.csproj @@ -15,6 +15,7 @@ + diff --git a/Tutorials/EchoServer/MainServer.cs b/Tutorials/EchoServer/MainServer.cs index 671a573..fd6110b 100644 --- a/Tutorials/EchoServer/MainServer.cs +++ b/Tutorials/EchoServer/MainServer.cs @@ -19,8 +19,8 @@ class MainServer : AppServer { public static SuperSocket.SocketBase.Logging.ILog MainLogger; - Dictionary> HandlerMap = new Dictionary>(); - CommonHandler CommonHan = new CommonHandler(); + //Dictionary> HandlerMap = new Dictionary>(); + //CommonHandler CommonHan = new CommonHandler(); IServerConfig m_Config; @@ -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("핸들러 등록 완료"); } @@ -74,7 +74,7 @@ public void CreateServer() CounterTh = new Thread(EchoCounter); CounterTh.Start(); - MainLogger.Info("서버 생성 성공"); + MainLogger.Info($"[{DateTime.Now}] 서버 생성 성공"); } catch(Exception ex) { @@ -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}"); } } @@ -106,7 +106,7 @@ 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}"); @@ -114,26 +114,25 @@ void OnConnected(NetworkSession session) 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 dataSource = new List(); + 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); } } diff --git a/Tutorials/EchoServer/PacketHandlers.cs b/Tutorials/EchoServer/PacketHandlers.cs deleted file mode 100644 index de16dc5..0000000 --- a/Tutorials/EchoServer/PacketHandlers.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EchoServer -{ - public class PacketData - { - public NetworkSession session; - public EFBinaryRequestInfo reqInfo; - } - - public enum PACKETID : int - { - REQ_ECHO = 101, - } - - public class CommonHandler - { - public void RequestEcho(NetworkSession session, EFBinaryRequestInfo requestInfo) - { - var totalSize = (Int16)(requestInfo.Body.Length + EFBinaryRequestInfo.HEADERE_SIZE); - - List dataSource = new List(); - dataSource.AddRange(BitConverter.GetBytes(totalSize)); - dataSource.AddRange(BitConverter.GetBytes((Int16)PACKETID.REQ_ECHO)); - dataSource.AddRange(new byte[1]); - dataSource.AddRange(requestInfo.Body); - - session.Send(dataSource.ToArray(), 0, dataSource.Count); - } - } - - public class PK_ECHO - { - public string msg; - } -}