全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2424
推到 Plurk!
推到 Facebook!

請教IdHTTPServer的問題..

尚未結案
旅者
一般會員


發表:5
回覆:9
積分:2
註冊:2004-02-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-07-20 13:49:51 IP:203.74.xxx.xxx 未訂閱
在下試著寫了一個server端及一個client端的測試程式 server端使用IdHTTPServer元件,負責接收client端的要求,並作出回應 client端使用IdHTTP元件,負責不斷的送出要求 經在下的測試結果...當只有一個Client端不斷送出要求時,server端正常的回應這些要求 但當兩個client端(在下測試時用了兩台電腦當client端)一起不停的對server送出要求時, server端常會觸發OnException事件,訊息通常是Invalid pointer operation..... 請問有人知道這問題要如何解決嗎?? 發表人 - 旅者 於 2004/07/20 15:48:24
microbean
初階會員


發表:1
回覆:43
積分:38
註冊:2004-04-09

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-07-22 17:35:44 IP:210.58.xxx.xxx 未訂閱
這可能要看 你在 server 上的 OnExecute 做了什麼. 兩個 connection 同時操作時 , 在 onExecute 就要注意 同時進入的問題 , 裡面相關的資源如果控制不當 , 很可能就會有問題. _= 沒事就 winsock 一下 =_
旅者
一般會員


發表:5
回覆:9
積分:2
註冊:2004-02-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-07-26 10:23:01 IP:203.74.xxx.xxx 未訂閱
引言: 這可能要看 你在 server 上的 OnExecute 做了什麼. 兩個 connection 同時操作時 , 在 onExecute 就要注意 同時進入的問題 , 裡面相關的資源如果控制不當 , 很可能就會有問題. _= 沒事就 winsock 一下 =_
感謝您的回覆^^ 小弟是用OnCommandGet 取得request,不過,狀況可能一樣...因為經測試狀況來判斷,問題是發生在OnConnect後,進入OnCommandGet前或剛好死在這..,所以的確很有可能如您所述.... 不知能否請您教導在下該如何避免此狀況呢?? 在下的OnCommandGet中只做以下的處理: void __fastcall TMainForm::IdHTTPServer1CommandGet(TIdPeerThread *AThread, TIdHTTPRequestInfo *RequestInfo, TIdHTTPResponseInfo *ResponseInfo) { ResponseInfo->ContentText = "a"; MainForm->iRequestCnt ; MainForm->iMaxRequest ; } 不知是哪裡有問題...這狀況已困擾在下許久..請大家不吝賜教..感謝..^^
microbean
初階會員


發表:1
回覆:43
積分:38
註冊:2004-04-09

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-08-05 17:32:26 IP:210.58.xxx.xxx 未訂閱
問題大概在這邊 MainForm->iRequestCnt ; MainForm->iMaxRequest ; 先把這兩行拿掉測試 , 如果正常在往下做 有兩種方法 : 1. 把 iRequestCnt , iMaxRequest 設定成 global 變數, 2. 使用 AThread->Synchronize() 呼叫另一個 func 對 MainForm->iRequestCnt,MainForm->iMaxRequest 此兩個變數存取 _= 沒事就 winsock 一下 =_
旅者
一般會員


發表:5
回覆:9
積分:2
註冊:2004-02-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-08-16 13:49:15 IP:203.74.xxx.xxx 未訂閱
引言: 問題大概在這邊 MainForm->iRequestCnt ; MainForm->iMaxRequest ; 先把這兩行拿掉測試 , 如果正常在往下做 有兩種方法 : 1. 把 iRequestCnt , iMaxRequest 設定成 global 變數, 2. 使用 AThread->Synchronize() 呼叫另一個 func 對 MainForm->iRequestCnt,MainForm->iMaxRequest 此兩個變數存取 _= 沒事就 winsock 一下 =_
先謝謝Microbean提供的意見..^^ 在下依您的意見作了測試,不過還是會出現Exception...而且..一段時間後,竟然server端竟自行結束程式了!!...T_T 另外,在下也安裝了Indy 9.0.14..也同樣會出現Exception..T_T
microbean
初階會員


發表:1
回覆:43
積分:38
註冊:2004-04-09

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-08-17 17:29:31 IP:210.58.xxx.xxx 未訂閱
把你的程式 client and server 貼上來研究看看 我測試過每0.5 秒做一次 並沒有你的這個問題... _= 沒事就 winsock 一下 =_
旅者
一般會員


發表:5
回覆:9
積分:2
註冊:2004-02-13

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-08-18 15:09:39 IP:203.74.xxx.xxx 未訂閱
以下是Server端    #include  #include #pragma hdrstop #include "Unit1.h" #include "Global.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TMainForm *MainForm; //--------------------------------------------------------------------------- __fastcall TMainForm::TMainForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TMainForm::TrigBtnClick(TObject *Sender) { MainForm->IdHTTPServer1->DefaultPort = PortEdit->Text.ToInt(); if (PortEdit->Text.ToInt()!=443) MainForm->IdHTTPServer1->Intercept = NULL; MainForm->iRequestCnt = 0; MainForm->iMaxRequest = 0; MainForm->iUnitTime = CountEdit->Text.ToInt()*60; MainForm->iTimeCnt = 0; Timer1->Interval = MainForm->iUnitTime*1000; Timer1->Enabled = true; IdHTTPServer1->Active = true; MsgMemo->Lines->Add("*****開始listen*****"); } //--------------------------------------------------------------------------- void __fastcall TMainForm::StopBtnClick(TObject *Sender) { IdHTTPServer1->Active = false; Timer1->Enabled = false; MsgMemo->Lines->Add("*****停止listen*****"); MsgMemo->Lines->Add("單位時間(sec):" AnsiString(MainForm->iUnitTime)); MsgMemo->Lines->Add("已服務要求數:" AnsiString(MainForm->iRequestCnt)); MsgMemo->Lines->Add("累計時間(min):" AnsiString(MainForm->iTimeCnt)); MsgMemo->Lines->Add("共服務要求數:" AnsiString(MainForm->iMaxRequest)); if (MainForm->SaveDialog1->Execute()) { MainForm->MsgMemo->Lines->SaveToFile(MainForm->SaveDialog1->FileName); } } //--------------------------------------------------------------------------- void __fastcall TMainForm::AddCnt(void) { MainForm->iRequestCnt ; MainForm->iMaxRequest ; } //--------------------------------------------------------------------------- void __fastcall TMainForm::IdHTTPServer1CommandGet(TIdPeerThread *AThread, TIdHTTPRequestInfo *RequestInfo, TIdHTTPResponseInfo *ResponseInfo) { // MsgMemo->Lines->Add("CommandGet"); ResponseInfo->ContentText = "a"; AThread->Synchronize(AddCnt); } //--------------------------------------------------------------------------- void __fastcall TMainForm::IdServerInterceptOpenSSL1GetPassword( AnsiString &Password) { Password = PASSWORD; } //--------------------------------------------------------------------------- void __fastcall TMainForm::FormCreate(TObject *Sender) { char cPath[MAX_PATH_LENGTH]; ::GetCurrentDirectory(MAX_PATH_LENGTH,cPath); MainForm->sCurrentPath = AnsiString(cPath); IdServerInterceptOpenSSL1->SSLOptions->CertFile = MainForm->sCurrentPath CERTIFICATE_KEY; IdServerInterceptOpenSSL1->SSLOptions->RootCertFile = MainForm->sCurrentPath CERTIFICATE_KEY; IdServerInterceptOpenSSL1->SSLOptions->KeyFile = MainForm->sCurrentPath PRIVATE_KEY; } //--------------------------------------------------------------------------- void __fastcall TMainForm::Timer1Timer(TObject *Sender) { // 到達單位時間,顯示服務要求數 MainForm->iTimeCnt ; MsgMemo->Lines->Add("*********************************************"); MsgMemo->Lines->Add("單位時間(sec):" AnsiString(MainForm->iUnitTime)); MsgMemo->Lines->Add("已服務要求數:" AnsiString(MainForm->iRequestCnt)); MsgMemo->Lines->Add("累計時間(min):" AnsiString(MainForm->iTimeCnt)); MsgMemo->Lines->Add("共服務要求數:" AnsiString(MainForm->iMaxRequest)); MainForm->iRequestCnt = 0; } //--------------------------------------------------------------------------- void __fastcall TMainForm::ThreadException(TObject *Sender,Exception *e) { MsgMemo->Lines->Add(e->Message); } //--------------------------------------------------------------------------- void __fastcall TMainForm::IdHTTPServer1Connect(TIdPeerThread *AThread) { // MsgMemo->Lines->Add("Connect"); AThread->OnException = ThreadException; } //--------------------------------------------------------------------------- 以下是Client端 #include #include #pragma hdrstop #include "Unit1.h" #include "Global.h" #include "ConnectThread.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TMainForm *MainForm; //--------------------------------------------------------------------------- __fastcall TMainForm::TMainForm(TComponent* Owner) : TForm(Owner) { MainForm->sURL = DEFAULT_URL; MainForm->tpResponseStream = new TStringStream(MainForm->sResponse); MainForm->sRequest = new TStringList; MainForm->iRequestCnt = 0; } //--------------------------------------------------------------------------- void __fastcall TMainForm::ConnectBtnClick(TObject *Sender) { int iMaxThreads,iCnt; MainForm->sURL = MainForm->URL_Edit->Text; MainForm->sRequest->Text = MainForm->RequestEdit->Text; MainForm->iPort = PortEdit->Text.ToInt(); IdHTTP1->Host = MainForm->sURL; IdHTTP1->Port = MainForm->iPort; if (MainForm->iPort == 443) { MainForm->bHTTPsFlag = true; IdConnectionInterceptOpenSSL1->SSLOptions->Method = sslvSSLv23; IdConnectionInterceptOpenSSL1->SSLOptions->Mode = sslmClient; IdConnectionInterceptOpenSSL1->SSLOptions->VerifyDepth = 0; // IdHTTP1->InterceptEnabled = false; IdHTTP1->Intercept = IdConnectionInterceptOpenSSL1; IdHTTP1->InterceptEnabled = true; } else { MainForm->bHTTPsFlag = false; IdHTTP1->InterceptEnabled = false;; IdHTTP1->Intercept = NULL; } iMaxThreads = MainForm->ThreadEdit->Text.ToInt(); Timer1->Interval = TimeEdit->Text.ToInt()*60000; Timer1->Enabled = true; while(1) { for (iCnt=0;iCntPost(MainForm->sURL,MainForm->sRequest,(TStream *)MainForm->tpResponseStream); MainForm->iRequestCnt ; MainForm->MsgMemo->Lines->Add("第" AnsiString(MainForm->iRequestCnt) "個連線要求"); // 處理系統Message佇列 Application->ProcessMessages(); } if (!MainForm->LoopRadioBtn->Checked) break; } Timer1->Enabled = false; } //--------------------------------------------------------------------------- void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action) { MainForm->LoopRadioBtn->Checked = false; delete MainForm->tpResponseStream; delete MainForm->sRequest; // Application->Terminate(); } //--------------------------------------------------------------------------- 歡迎指教...謝謝...^^
系統時間:2024-05-13 13:24:45
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!