Socket 連線一問 |
缺席
|
BGman
初階會員 發表:28 回覆:85 積分:42 註冊:2003-01-10 發送簡訊給我 |
當Socket連線並執行下面的程式Form 都會卡住
且都無法讀回任何資訊(最後都是No reply),
請問是否有地方沒注意到或是有誤???
void __fastcall TForm1::ClientSocketConnect(TObject *Sender, TCustomWinSocket *Socket) { TWinSocketStream *wnscktstrmMain; AnsiString Directory = "http://tw.yahoo.com/"; try { wnscktstrmMain = new TWinSocketStream(Socket, 60000); AnsiString buf; buf = "GET " Directory " HTTP/1.0 nrnr" " User-Agent: MechaMozilla/4.0 (compatible; MSIE 5.0 ; Windows 98) nrnr" " Accept: text/* nrnr"; if ( wnscktstrmMain->Write(buf.c_str(),buf.Length()) ) { //if write succeeded, read from stream char point[10000]; memset(point, 0, 10000); // initialize the buffer if( wnscktstrmMain->Read(point,10000) ) { point[10000]='0'; Memo1->Text=Memo1->Text buf; } else ShowMessage("No reply"); } else { ShowMessage("Connection timed out"); } } __finally { delete wnscktstrmMain; } } |
RaynorPao
版主 發表:139 回覆:3622 積分:7025 註冊:2002-08-12 發送簡訊給我 |
引言: 當Socket連線並執行下面的程式Form 都會卡住 且都無法讀回任何資訊(最後都是No reply), 請問是否有地方沒注意到或是有誤???BGman 你好: 能不能先請問一下~~你的目的是什麼呢?? --void __fastcall TForm1::ClientSocketConnect(TObject *Sender, TCustomWinSocket *Socket) { TWinSocketStream *wnscktstrmMain; AnsiString Directory = "http://tw.yahoo.com/"; try { wnscktstrmMain = new TWinSocketStream(Socket, 60000); AnsiString buf; buf = "GET " Directory " HTTP/1.0 nrnr" " User-Agent: MechaMozilla/4.0 (compatible; MSIE 5.0 ; Windows 98) nrnr" " Accept: text/* nrnr"; if ( wnscktstrmMain->Write(buf.c_str(),buf.Length()) ) { //if write succeeded, read from stream char point[10000]; memset(point, 0, 10000); // initialize the buffer if( wnscktstrmMain->Read(point,10000) ) { point[10000]='0'; Memo1->Text=Memo1->Text buf; } else ShowMessage("No reply"); } else { ShowMessage("Connection timed out"); } } __finally { delete wnscktstrmMain; } }
------
-- 若您已經得到滿意的答覆,請適時結案!! -- -- 欲知前世因,今生受者是;欲知來世果,今生做者是 -- -- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 -- |
BGman
初階會員 發表:28 回覆:85 積分:42 註冊:2003-01-10 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |