unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdGlobal, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
ComboBox1: TComboBox;
Label1: TLabel;
Label2: TLabel;
ComboBox2: TComboBox;
Memo1: TMemo;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure ComboBox2CloseUp(Sender: TObject);
procedure ComboBox1CloseUp(Sender: TObject);
private
{ Private-Deklarationen }
TCPClient: TIdTCPClient;
procedure ClientInit;
procedure ClientExit;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
TCPClient.Connect;
{
if TCPClient.Connected then begin
TCPClient.IOHandler.WriteLn('$help target');
TCPClient.Disconnect;
end;
}
end;
procedure TForm1.ClientInit;
begin
TCPClient := TIdTCPClient.Create(self);
with TCPClient
do begin
ConnectTimeout := 5000;
//Limit vorgeben, damit Server reagieren kann
TCPClient.Host := ComboBox1.Text;
IPVersion := Id_IPv4;
Port := StrToInt(ComboBox2.text);
ReadTimeout := 500;
//Limit für Lesen, ich nehme an, von Servernachrichten
end;
end;
procedure TForm1.ClientExit;
begin
TCPClient.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ClientInit;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
ClientExit;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
TCPClient.Disconnect;
end;
//IP Adresse Ändern
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
TCPClient.Host := ComboBox1.Text;
end;
//Kommando an den Server übergeben, wenn Verbindung Ok.
procedure TForm1.Button3Click(Sender: TObject);
var LastCmd: Integer;
begin
LastCmd := Memo1.Lines.Count;
if TCPClient.Connected
then
begin
if LastCmd>0
then
TCPClient.IOHandler.WriteLn(Memo1.Lines.Strings[LastCmd-1]);
end;
end;
//Port einstellen -> Vorgabe 50000
procedure TForm1.ComboBox2CloseUp(Sender: TObject);
begin
TCPClient.Port := StrToInt(ComboBox2.text);
ShowMessage('
Neuer Port'+IntToStr(TCPClient.Port));
end;
//IP Adresse einstellen -> Vorgabe 127.0.0.1 -> Eistellbar-> eigene IP,
//derzeit auch im LAN automatisch vergeben. Habe diese automatisch vorgegebene IP Adresse
//verwendet
procedure TForm1.ComboBox1CloseUp(Sender: TObject);
begin
TCPClient.Host := ComboBox1.Text;
ShowMessage('
Neuer Host: '+TCPClient.Host);
end;
end.