請問 ServerSocket 改成 stThreadBlocking 之後如何收資料 |
|
whyzn
中階會員 ![]() ![]() ![]() 發表:46 回覆:149 積分:54 註冊:2002-06-16 發送簡訊給我 |
請問前輩
原來我用 ClientSocket (ctNonBlocking) 連 ServerSocket (stBLocking) 的方式 Srever 可以接收到資料 現在試著把 ServerSocket 改成 stThreadBlocking 後 原來在 OnClientRead 的 Code 就沒執行了 請問 Server 對每個連上來的 Client 新產生的 Thread 我該把 Code 寫在哪裡 請指導一下 謝謝
------
●○○○○○●○○○○○● 竹密不妨水過,山高無礙雲飛 |
hagar
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
在 OnGetThreaad Event 下, 參考:
http://info.borland.com/techpubs/delphi/delphi5/dg/wsocket.html#31520 |
whyzn
中階會員 ![]() ![]() ![]() 發表:46 回覆:149 積分:54 註冊:2002-06-16 發送簡訊給我 |
===================引 用 文 章=================== 在 OnGetThreaad Event 下, 參考: http://info.borland.com/techpubs/delphi/delphi5/dg/wsocket.html#31520 感謝 hagar 老兄,可以收到資料了 接著請問 procedure TForm1.ServerSocket1GetThread(Sender: TObject; ClientSocket: TServerClientWinSocket; var SocketThread: TServerClientThread); begin // 底下建立了 thread 之後,thread 何時會消滅 SocketThread := TMYServerThread.Create(False, ClientSocket); end; 在 MyServerThread 中是否要自行處裡 thread 消滅的事情 procedure TMyServerThread.ClientExecute; var Stream : TWinSocketStream; Buffer : array[0 .. 9] of Char; begin { make sure connection is active } while (not Terminated) and ClientSocket.Connected do begin try Stream := TWinSocketStream.Create(ClientSocket, 60000); try FillChar(Buffer, 10, 0); { initialize the buffer } { give the client 60 seconds to start writing } if Stream.WaitForData(60000) then begin if Stream.Read(Buffer, 10) = 0 then { if can't read in 60 seconds } ClientSocket.Close; { close the connection } { now process the request } ... end else ClientSocket.Close; { if client doesn't start, close } finally Stream.Free; end; except HandleException; end; end; // 或者離開上述迴圈 thread 就自動結束了 end; 或者我需要為創建的 thread 作 free 的動作
------
●○○○○○●○○○○○● 竹密不妨水過,山高無礙雲飛 |
hagar
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
procedure TForm1.ServerSocket1GetThread(Sender: TObject;
ClientSocket: TServerClientWinSocket; var SocketThread: TServerClientThread); begin SocketThread := TMYServerThread.Create(False, ClientSocket); SocketThread.FreeOnTerminate := True; // 加這一行試試 end; |
whyzn
中階會員 ![]() ![]() ![]() 發表:46 回覆:149 積分:54 註冊:2002-06-16 發送簡訊給我 |
hagar 兄:
procedure TForm1.ServerSocket1GetThread(Sender: TObject;
ClientSocket: TServerClientWinSocket; var SocketThread: TServerClientThread); begin SocketThread := TMYServerThread.Create(False, ClientSocket); SocketThread.FreeOnTerminate := True; // 加這一行試試 end; 我知道了 SocketThread 在離開 Execute Procedure 後會自行 Free 但若我將來要在 MAin Thread 下指令終結 ScoketThread 該如何做呢
------
●○○○○○●○○○○○● 竹密不妨水過,山高無礙雲飛 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |