unit uMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
ExtCtrls, ScktComp;
type
TKECServerMonitoring =
class(TService)
Timer: TTimer;
procedure ServiceExecute(Sender: TService);
procedure ServiceAfterInstall(Sender: TService);
procedure ServiceBeforeUninstall(Sender: TService);
procedure ServiceCreate(Sender: TObject);
procedure ServiceStart(Sender: TService;
var Started: Boolean);
procedure ServiceStop(Sender: TService;
var Stopped: Boolean);
procedure TimerTimer(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
Client: TClientSocket;
Server: TServerSocket;
function GetServiceController: TServiceController;
override;
end;
var
KECServerMonitoring: TKECServerMonitoring;
implementation
{$R *.DFM}
{##############################################################################}
{###################### ################################}
{###################### Main Program ################################}
{###################### ################################}
{##############################################################################}
procedure ServiceController(CtrlCode: DWord);
stdcall;
begin
KECServerMonitoring.Controller(CtrlCode);
end;
function TKECServerMonitoring.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TKECServerMonitoring.ServiceAfterInstall(Sender: TService);
begin
//
end;
procedure TKECServerMonitoring.ServiceBeforeUninstall(Sender: TService);
begin
Server.Active := FALSE;
end;
procedure TKECServerMonitoring.ServiceCreate(Sender: TObject);
begin
//Initialisierung des Objekts (ältere Delphi-Versionen)
Server := TServerSocket.Create(Self);
// Initial Server Verbindung damit der Client Verbindung aufnehmen kann
Server.Port := 29979;
Server.Active := TRUE;
end;
procedure TKECServerMonitoring.ServiceStart(Sender: TService;
var Started: Boolean);
begin
Timer.Enabled := TRUE;
end;
procedure TKECServerMonitoring.ServiceExecute(Sender: TService);
begin
while not Terminated
do
begin
ServiceThread.ProcessRequests(TRUE);
// CPU Last ist damit nicht 100%
end;
end;
procedure TKECServerMonitoring.ServiceStop(Sender: TService;
var Stopped: Boolean);
begin
Timer.Enabled := FALSE;
end;
procedure TKECServerMonitoring.TimerTimer(Sender: TObject);
begin
if Server.Active = FALSE
then
begin
Server.Port := 29979;
Server.Active := TRUE;
end;
end;
end.