unit U_Spy_Client;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, ExtCtrls;
const IP = '
XXX.XXX.XXX.XXX';
PORT = XXXXX;
TimeIntervCon = 1000;
Type
TClient =
class(TObject)
private
CS1: TClientSocket;
TimerCon: TTimer;
iCon :
String;
iDis :
String;
procedure Disco;
procedure CS1Connect(Sender: TObject; Socket: TCustomWinSocket);
procedure CS1Disconnect(Sender: TObject; Socket: TCustomWinSocket);
procedure CS1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
procedure CS1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure TimerConTime(Sender: TObject);
procedure Initial;
procedure SockFree;
public
constructor Create;
destructor Destroy;
override;
end;
implementation
constructor TClient.Create;
begin
//Sockel------------------------
Initial;
//Timer Verbindung aufbauen-------------------------
TimerCon := TTimer.Create(
nil);
TimerCon.Interval := TimeIntervCon;
TimerCon.OnTimer := TimerConTime;
TimerCon.Enabled:=True;
end;
destructor TClient.Destroy;
begin
//Timer abklemmen
TimerCon.Enabled := false;
TimerCon.OnTimer :=
nil;
TimerCon.Free;
//Socket abklemmen
SockFree;
inherited;
end;
procedure TClient.Disco;
begin
Cs1.Close;
end;
procedure TClient.CS1Connect(Sender: TObject; Socket: TCustomWinSocket);
begin
iCon := '
Verbindung Aufgebaut: ' + datetimetostr(Now);
end;
procedure TClient.CS1Disconnect(Sender: TObject; Socket: TCustomWinSocket);
begin
iDis := '
VerbindungGetrennt: ' + datetimetostr(Now);
end;
procedure TClient.CS1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
Disco;
ErrorCode := 0;
end;
procedure TClient.CS1Read(Sender: TObject; Socket: TCustomWinSocket);
var s:
String;
begin
s := Socket.ReceiveText;
if s = '
Test'
then
Begin
Disco;
Application.Terminate;
End
end;
procedure TClient.TimerConTime(Sender: TObject);
begin
if not(CS1.Socket.Connected)
then
Begin
SockFree;
Initial;
CS1.Open;
End;
end;
procedure TClient.Initial;
begin
CS1 := TClientSocket.Create(
nil);
cs1.Host :=
IP;
CS1.Port := Port;
CS1.OnConnect := CS1Connect;
CS1.OnDisconnect := CS1Disconnect;
CS1.OnError := CS1Error;
CS1.OnRead := CS1Read;
end;
procedure TClient.SockFree;
begin
if CS1.Active
then Cs1.Close;
CS1.OnConnect :=
nil;
CS1.OnDisconnect :=
nil;
CS1.OnError :=
nil;
CS1.OnRead :=
nil;
Cs1.Free;
end;
end.