unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPServer, Borland.Vcl.StdCtrls,
  System.ComponentModel, IdContext;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    ListBox1: TListBox;
    IdTCPServer1: TIdTCPServer;
    Label1: TLabel;
    Label2: TLabel;
    procedure IdTCPServer1Disconnect(AContext: TIdContext);
    procedure IdTCPServer1Connect(AContext: TIdContext);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.nfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Enabled:=False;
idTCPServer1.Bindings.Add.IP:=Edit1.Text;
idTCPServer1.Bindings.Add.Port:=StrtoInt(Edit2.Text);
idTCPServer1.Active:=true;
end;

procedure TForm1.IdTCPServer1Connect(AContext: TIdContext);
begin
ListBox1.Items.Add(Acontext.Connection.Socket.Binding.PeerIP);
end;

procedure TForm1.IdTCPServer1Disconnect(AContext: TIdContext);
var i: Integer;
begin
for i:=0 to ListBox1.Count-1 do
  if ListBox1.Items[i]=Acontext.Connection.Socket.Binding.PeerIP then
    ListBox1.Items.Delete(i);

end;

end.
