You don't need a thread for every tcp/ip socket connection. When your 
application works fine in a form, you can reuse this form when create and 
activate it from the start of service.

kind regards,
Ronny Aerts
Belgium

  ----- Original Message ----- 
  From: dts124 
  To: [email protected] 
  Sent: Saturday, April 21, 2007 1:37 PM
  Subject: [Norton AntiSpam] [delphi-en] Re: service with threads for socket 
connections


  --- In [email protected], "dts124" <[EMAIL PROTECTED]> wrote:

  there was a suggestion to use WaitForSingleObject for thread to wait
  for next message:

  procedure TEchoThread.Execute;
  var
  Str: string;
  begin
  while not Terminated do
  begin
  if WaitForSingleObject(SomeEvent, INFINITE) = WAIT_OBJECT_0 then
  begin
  begin
  Str := IntToStr(FSockHnd) +' '+ IntToStr(FConnIndx) +' '+ FBuff;

  Service1.ServerSocket1.Socket.Connections[FConnIndx].SendText(Str);
  end;
  end;
  end;
  end;

  Question: how to pass ServerSocket1 OnClientRead event of the main
  thread to WaitForSingleObject function of thread?

  dts124
  ------------------------------
  >
  > I am trying to port a working "Form" application (medical DICOM
  > worklist server) to service. The application is answering to multiple
  > possibly concurrent connections, so i assume there must be separate
  > thread for each existing connection. Connections (and threads) are
  > closed after the requested data is sent.
  > 
  > For now my test service just echoes back text string received from
  > client with addition of connection handle number.
  > 
  > Problem:
  > after 1-st client connection CPU usage of this service is 50%(probably
  > because my CPU is Pentium D), after 2nd - 99% and remains 99% until
  > service is stopped regardless that all clients are disconnected.
  > 
  > After i added Sleep(10); into 
  > "while not Terminated do" loop of procedure TEchoThread.Execute;
  > CPU usage dropped to 0, now it seems OK, but is this the right way to
  > arrange service with threads for socket connections?
  >



   

[Non-text portions of this message have been removed]

Reply via email to