unit UMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdAntiFreezeBase, IdAntiFreeze;
// ------- NETWORK PROTOKOL --------
// v001
type
TNetConfig =
record
data : boolean;
CMD :
string[20];
SIP :
string[16];
DIP :
string[16];
end;
// ---------------------------------
type
TForm1 =
class(TForm)
tcpClient: TIdTCPClient;
GroupBox1: TGroupBox;
btnConnect: TButton;
edtHost: TEdit;
edtPort: TEdit;
edtUser: TEdit;
edtPass: TEdit;
btnDisconnect: TButton;
Label1: TLabel;
Label2: TLabel;
memLog: TMemo;
IdAntiFreeze1: TIdAntiFreeze;
procedure FormDestroy(Sender: TObject);
procedure btnConnectClick(Sender: TObject);
procedure btnDisconnectClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
inloop : integer = 1;
//default value = 1 (while in thread = stop !)
implementation
{$R *.DFM}
function netscan(P : pointer): integer;
var
Data:TNetConfig;
begin
// Code !
while inloop =0
do
begin
//read data from server
// PROBLEM IST VON HIER
Form1.tcpclient.ReadBuffer(Data,sizeof(Data));
// BIS HIER ;)
if Data.data = false
then
Form1.memLog.Lines.add('
STR:'+Data.CMD)
else
Form1.memLog.Lines.add('
CMD:'+Data.CMD);
// read thread status (inloop value)
sleep(1);
Form1.Label1.Caption := inttostr(inLoop);
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
//set inLoop to 1 (stops while in thread)
InterlockedExchange(inLoop, 1);
// TCP Disconnection !
tcpclient.Disconnect;
end;
procedure TForm1.btnConnectClick(Sender: TObject);
var
ThreadID: LongWord;
p: Pointer;
begin
// Server-IP (Data from edtHost)
tcpclient.Host := edtHost.Text;
// Server-Port (Data from edtPort)
tcpclient.Port := strtoint(edtPort.Text);
// Connection to server
tcpClient.Connect;
// If connection is succesfull, then start the thread !
if tcpClient.Connected
then
begin
memLog.Lines.Add('
Connected to server!');
//set inLoop to 0 (while in thread can run)
InterlockedExchange(inLoop, 0);
//start thread !
CloseHandle(BeginThread(
nil, 0, @netscan, p, 0, ThreadID));
end;
end;
procedure TForm1.btnDisconnectClick(Sender: TObject);
begin
//set inLoop to 1 (stops while in thread)
InterlockedExchange(inLoop, 1);
end;
end.