public void Hello() { MsgModel msg = new MsgModel(); msg.SetCmd(CmdType.HELLO_MSG); msg.Guid = this.Guid; msg.UserName = "******"; msg.Msg = this.Guid; WriteMsg(msg); }
/// <summary> /// 통신 서비스 함수. /// </summary> private void ServiceOperation() { Console.WriteLine("******** Service Start ******** "); while (ServiceFlag) { Thread.Sleep(300); if (GetMsgQueue().Count > 0) { var msgModel = GetMsgQueue().Dequeue(); switch (msgModel.GetCmd()) { case CmdType.HELLO_ACK: Console.WriteLine($"## ONLINE CLIENT - #{msgModel.Guid}"); break; case CmdType.CLIENT_MSG: //클라이언트로 메시지 수신 { Console.WriteLine($"# SENDING MSG : [{msgModel.SendFormMsg()}]"); for (int i = 0; i < GetClientList().Count; i++) { Client cl = GetClientList().ElementAt(i).Value; if (cl.Guid == msgModel.Guid) { MsgModel res = msgModel; res.SetCmd(CmdType.CLIENT_ACK); cl.WriteMsg(res); } else { MsgModel res = msgModel; res.SetCmd(CmdType.BROAD_MSG); cl.WriteMsg(res); } } break; } case CmdType.BROAD_ACK: break; case CmdType.FILE_INFO_REQ: { if (GetClientList().TryGetValue(msgModel.Guid, out Client cl)) { if (GetFileList().Count < 1) { MsgModel res = msgModel; res.UserName = "******"; res.SetCmd(CmdType.FILE_INFO_REQ); res.Msg = "[WARN] There are NO Registered Files!"; cl.WriteMsg(res); } else { foreach (var file in GetFileList().Values) { MsgModel res = msgModel; res.UserName = "******"; res.SetCmd(CmdType.FILE_INFO_REQ); res.Msg = $"[{file.Guid}] {file.Name} / {file.Size} Byte"; cl.WriteMsg(res); } } } break; } case CmdType.CLOSE_REQ: { if (GetClientList().TryGetValue(msgModel.Guid, out Client cl)) { MsgModel res = msgModel; res.SetCmd(CmdType.CLOSE_ACK); cl.WriteMsg(res); cl.Dispose(); } break; } case CmdType.ALIVE: { if (GetClientList().TryGetValue(msgModel.Guid, out Client cl)) { MsgModel res = msgModel; res.SetCmd(CmdType.ALIVE_ACK); cl.WriteMsg(res); } break; } case CmdType.ERROR_ACK: case CmdType.UNKNOWN: default: break; } } } Console.WriteLine("******** Service Finished ******** "); }