static void PacketSend(Packet packet, string suburl, TestClientBridge bridge) { var buffer = packet.Pack(); var request = WebRequest.CreateHttp("http://127.0.0.1:8080" + suburl); request.Method = "POST"; request.ContentType = "application/octet-stream"; request.ContentLength = buffer.Length; using (var stream = request.GetRequestStream()) { stream.Write(buffer, 0, buffer.Length); } try { var response = request.GetResponse() as HttpWebResponse; using (var stream = response.GetResponseStream()) { var length = (int)response.ContentLength; var readbuf = new byte[length]; stream.Read(readbuf, 0, length); bridge.m_poolCtrl.CallReceive(Packet.Unpack(readbuf)); } } catch (WebException e) // 웹 연결이 에러 코드를 주면 Server Error로 처리한다. { bridge.m_poolCtrl.CallReceiveServerError(packet.header.messageType); } }
public TestClient() { m_authClient = new TestAuthClient(); m_authPP = new ClientProcedurePool(); m_authPP.AddPairParamType <ReqLogin, RespLogin>("ReqLogin", "RespLogin"); m_authPP.AddPairParamType <EmptyParam, EmptyParam>("ReqCheckAuth", "RespCheckAuth"); var authBridge = new TestClientBridge(); m_authPP.SetBridge(authBridge); m_authPP.SetAuthClientObject(m_authClient); authBridge.m_poolCtrl.SetSendDelegate((packet) => PacketSend(packet, "/auth/", authBridge)); m_authPP.Start(); // m_userPP = new ClientProcedurePool(); m_userPP.AddPairParamType <ReqNewUser, RespNewUser>("ReqNewUser", "RespNewUser"); m_userPP.AddPairParamType <EmptyParam, EmptyParam>("ReqDeleteUser", "RespDeleteUser"); m_userPP.AddPairParamType <ReqBlindUser, EmptyParam>("ReqBlindUser", "RespBlindUser"); m_userPP.AddPairParamType <ReqUserInfo, RespUserInfo>("ReqUserInfo", "RespUserInfo"); var userBridge = new TestClientBridge(); m_userPP.SetBridge(userBridge); m_userPP.SetAuthClientObject(m_authClient); userBridge.m_poolCtrl.SetSendDelegate((packet) => PacketSend(packet, "/user/", userBridge)); m_userPP.Start(); // m_postPP = new ClientProcedurePool(); m_postPP.AddPairParamType <ReqLookupPosting, RespLookupPosting>("ReqLookupPosting", "RespLookupPosting"); m_postPP.AddPairParamType <ReqShowPosting, RespShowPosting>("ReqShowPosting", "RespShowPosting"); m_postPP.AddPairParamType <ReqNewPosting, RespPostingModify>("ReqNewPosting", "RespNewPosting"); m_postPP.AddPairParamType <ReqDeletePosting, RespDeletePosting>("ReqDeletePosting", "RespDeletePosting"); m_postPP.AddPairParamType <ReqBlindPosting, EmptyParam>("ReqBlindPosting", "RespBlindPosting"); m_postPP.AddPairParamType <ReqAddTag, RespAddTag>("ReqAddTag", "RespAddTag"); m_postPP.AddPairParamType <ReqDeleteTag, RespDeleteTag>("ReqDeleteTag", "RespDeleteTag"); var postBridge = new TestClientBridge(); m_postPP.SetBridge(postBridge); m_postPP.SetAuthClientObject(m_authClient); postBridge.m_poolCtrl.SetSendDelegate((packet) => PacketSend(packet, "/posting/", postBridge)); m_postPP.Start(); // m_reptPP = new ClientProcedurePool(); m_reptPP.AddPairParamType <ReqFileReport, RespFileReport>("ReqFileReport", "RespFileReport"); m_reptPP.AddPairParamType <ReqLookupReport, RespLookupReport>("ReqLookupReport", "RespLookupReport"); m_reptPP.AddPairParamType <ReqShowReport, RespShowReport>("ReqShowReport", "RespShowReport"); m_reptPP.AddPairParamType <ReqCloseReport, RespCloseReport>("ReqCloseReport", "RespCloseReport"); var reptBridge = new TestClientBridge(); m_reptPP.SetBridge(reptBridge); m_reptPP.SetAuthClientObject(m_authClient); reptBridge.m_poolCtrl.SetSendDelegate((packet) => PacketSend(packet, "/report/", reptBridge)); m_reptPP.Start(); // m_notiPP = new ClientProcedurePool(); m_notiPP.AddPairParamType <ReqPostNotice, EmptyParam>("ReqPostNotice", "RespPostNotice"); m_notiPP.AddPairParamType <ReqDeleteNotice, EmptyParam>("ReqDeleteNotice", "RespDeleteNotice"); m_notiPP.AddPairParamType <ReqLookupNotice, RespLookupNotice>("ReqLookupNotice", "RespLookupNotice"); m_notiPP.AddPairParamType <ReqShowNotice, RespShowNotice>("ReqShowNotice", "RespShowNotice"); var notiBridge = new TestClientBridge(); m_notiPP.SetBridge(notiBridge); m_notiPP.SetAuthClientObject(m_authClient); notiBridge.m_poolCtrl.SetSendDelegate((packet) => PacketSend(packet, "/notice/", notiBridge)); m_notiPP.Start(); }