title: Delphi - Simple TCP client / server using Indy to check clients status
body: <p>I started playing with Indy 10 (from Delphi XE3) and TCP connections recently. For now, I am trying to create a simple server application to check clients status. But when I try to deactivate TCPServer with some client already connected, clients do get disconnected but TCPServer stops answering.</p>
  
  <p>I read somewhere that TCPServer should handle client's disconnection without problems. Must I add some code on OnExecute event to solve this problem?</p>
  
  <p>Here is the code:</p>
  
  <pre><code>procedure TfrmMain.btnConnectClick(Sender: TObject);
  begin
    If (not TCPServer.Active) Then
    Try
      TCPServer.Bindings.Clear;
      With TCPServer.Bindings.Add Do
      Begin
        IP := '192.168.1.11';
        Port := StrToInt(edtPort.Text);
      end;
      TCPServer.Active := True;
    Except
      On E:Exception Do ShowMessage(E.Message);
    End
  end;
  
  procedure TfrmMain.btnDisconnectClick(Sender: TObject);
  begin
    If (TCPServer.Active) Then
    Try
      TCPServer.Active := False;
    Except
      On E:Exception Do ShowMessage(E.Message);
    End
  end;
  
  procedure TfrmMain.TCPServerConnect(AContext: TIdContext);
  var
    IdStackWin: TIdStackWindows;
  begin
    IdStackWin := TIdStackWindows.Create;
    With IdStackWin Do
    Try
      memLog.Lines.Add('Connected - ' + HostByAddress(AContext.Binding.PeerIP) + ' (' + AContext.Binding.PeerIP + ')');
    Finally
      IdStackWin.Free;
    end;
  end;
  
  
  procedure TfrmMain.TCPServerDisconnect(AContext: TIdContext);
  var
    IdStackWin: TIdStackWindows;
  begin
    IdStackWin := TIdStackWindows.Create;
    With IdStackWin Do
    Try
      memLog.Lines.Add('Disconnected - ' + HostByAddress(AContext.Binding.PeerIP) + ' (' + AContext.Binding.PeerIP + ')');
    Finally
      IdStackWin.Free;
    end;
  end;
  
  procedure TfrmMain.TCPServerExecute(AContext: TIdContext);
  begin
     Application.ProcessMessages;
  end;
  </code></pre>
  
  <p>Thanks!</p>