在idTCPServer控件如何检测到Client的非正常断开.或者在IdTCPClient如何检测到连接的非正常断开.还有TServerSocket和TClientSocket

解决方案 »

  1.   

    client端判断是否连网:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if GetSystemMetrics(SM_NETWORK) AND $01 = $01 then
        ShowMessage('Machine is attached to network') else
        ShowMessage('Machine is not attached to network');
    end;
      

  2.   

    procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
      Socket: TCustomWinSocket);
    var
      i,j:integer;
      s:string;
    begin
      j:=0;
      for i:=1 to clientcount do
      begin
         if clientsocket[i]=socket then
           j:=i;
      end;   if j=0 then
       begin
         application.MessageBox('通信出错9!','出错!',mB_OK);
         exit;
       end;   listbox1.Items.Delete(j-1);   s:=clientsocket[j].remoteaddress+'-'+clientuser[j]+'已经离开!';   for i:=j to clientcount-1 do
       begin
         clientsocket[i]:=clientsocket[i+1];
         clientuser[i]:=clientuser[i+1];
       end;   clientcount:=clientcount-1;
       edit1.Text:=inttostr(clientcount);
       memo1.Lines.Add(s);   for i:=1 to clientcount do
       begin
       clientsocket[i].SendText(s);
         end;
    end;