如何从服务端主动断开已经连接的客户端(附部分代码)? |
缺席
|
ww990
一般會員 發表:1 回覆:0 積分:0 註冊:2006-07-11 發送簡訊給我 |
type
PClient = ^TClient; TClient = record PeerIP: string[15]; { 客户端IP地址 } Thread: Pointer; { Pointer to thread } end; procedure Tmain.IdTCPServer1Connect(AContext: TIdContext); var sendcmd: string; NewClient: PClient; begin GetMem(NewClient, SizeOf(TClient)); NewClient.PeerIP := AContext.Binding.PeerIP; NewClient.Thread := AContext; AContext.Data := TObject(NewClient); try Clients.LockList.Add(NewClient); finally Clients.UnlockList; end; end; procedure Tmain.RzBitBtn9Click(Sender: TObject); var Bindings: TIdSocketHandles; i, ClientsCount: integer; begin //服务器启动 if not IdTCPServer1.Active then begin RzBitBtn9.Caption := '停止服务'; Bindings := TIdSocketHandles.Create(idTCPServer1); try try idTCPServer1.Bindings := Bindings; idTCPServer1.Active := True; except on E: Exception do ShowMessage(E.Message); end; finally Bindings.Free; end; Clients := TThreadList.Create; Clients.Duplicates := dupAccept; RefreshListDisplay; end else begin //服务器停止,断开客户端 try ClientsCount := Clients.LockList.Count; finally Clients.UnlockList; end; if (ClientsCount > 0) then begin case MessageBox(Handle, PChar('有连接的客户端,确定要停止服务吗?'), PChar('提示信息'), MB_ICONINFORMATION or MB_YESNO or MB_DEFBUTTON2) of IDYES: begin RzBitBtn9.Caption := '启动服务'; try for I := 0 to Clients.LockList.Count - 1 do begin 如何在此次编写代码断开已经连接的客户端?????????????????????????????????? end; finally Clients.UnlockList end; end; end; end; end; |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |