BuilderSpec
Programmer
Hi
New to threads and trying to create a simple Socket server to run as an application. The code i have is a Service Application straight from the File.. New.. Service Application and added a ServerSocket from the Internet tab.
The code I have then is below :
//---------------------------------------------------------------------------
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TService1 *Service1;
//---------------------------------------------------------------------------
__fastcall TService1::TService1(TComponent* Owner)
: TService(Owner)
{
}
TServiceController __fastcall TService1::GetServiceController(void)
{
return (TServiceController) ServiceController;
}
void __stdcall ServiceController(unsigned CtrlCode)
{
Service1->Controller(CtrlCode);
}
//---------------------------------------------------------------------------
void __fastcall TService1::ServerSocket1ClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
Socket->SendText("ACK");
}
//---------------------------------------------------------------------------
void __fastcall TService1::ServiceExecute(TService *Sender)
{
ServerSocket1->Active = true;
while (!Terminated)
{
Service1->ServiceThread->ProcessRequests(true);
}
ServerSocket1->Active = false;
}
//---------------------------------------------------------------------------
void __fastcall TService1::ServiceAfterInstall(TService *Sender)
{
DoStart() ;
}
//---------------------------------------------------------------------------
void __fastcall TService1::ServiceStart(TService *Sender, bool &Started)
{
ServiceThread->Priority = tpIdle ;
Started = true;
}
//---------------------------------------------------------------------------
What happens is this.. the code runs ok and i can connect to the socket server and send it a message.. it responds with the "ACK" message OK but then the program starts usning 99% CPU permanently.
I am guessing that the
while (!Terminated)
{
Service1->ServiceThread->ProcessRequests(true);
}
is the cause.. any idea what i should put there instead..the help file examples say i should just do what I have done.
Any ideas ?
Hope this helps!
Regards
BuilderSpec
New to threads and trying to create a simple Socket server to run as an application. The code i have is a Service Application straight from the File.. New.. Service Application and added a ServerSocket from the Internet tab.
The code I have then is below :
//---------------------------------------------------------------------------
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TService1 *Service1;
//---------------------------------------------------------------------------
__fastcall TService1::TService1(TComponent* Owner)
: TService(Owner)
{
}
TServiceController __fastcall TService1::GetServiceController(void)
{
return (TServiceController) ServiceController;
}
void __stdcall ServiceController(unsigned CtrlCode)
{
Service1->Controller(CtrlCode);
}
//---------------------------------------------------------------------------
void __fastcall TService1::ServerSocket1ClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
Socket->SendText("ACK");
}
//---------------------------------------------------------------------------
void __fastcall TService1::ServiceExecute(TService *Sender)
{
ServerSocket1->Active = true;
while (!Terminated)
{
Service1->ServiceThread->ProcessRequests(true);
}
ServerSocket1->Active = false;
}
//---------------------------------------------------------------------------
void __fastcall TService1::ServiceAfterInstall(TService *Sender)
{
DoStart() ;
}
//---------------------------------------------------------------------------
void __fastcall TService1::ServiceStart(TService *Sender, bool &Started)
{
ServiceThread->Priority = tpIdle ;
Started = true;
}
//---------------------------------------------------------------------------
What happens is this.. the code runs ok and i can connect to the socket server and send it a message.. it responds with the "ACK" message OK but then the program starts usning 99% CPU permanently.
I am guessing that the
while (!Terminated)
{
Service1->ServiceThread->ProcessRequests(true);
}
is the cause.. any idea what i should put there instead..the help file examples say i should just do what I have done.
Any ideas ?
Hope this helps!
Regards
BuilderSpec