<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>TataL_LoR's Feed - Programmer's Heaven</title>
    <link>http://www.programmersheaven.com/feed/User/143605/RSS.aspx</link>
    <description>Events at Programmer's Heaven related to the user TataL_LoR.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Wed, 22 May 2013 21:55:31 -0700</pubDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <item>
      <title>Synchronizing TCPServer with main thread</title>
      <link />
      <description>&lt;p&gt;Posted a 'new message on the Advanced Delphi forum.&lt;/p&gt;Hi guys!&lt;br /&gt;
&lt;br /&gt;
I'm building a server app that collects data from many clients (CPU loads) using Indy components (TIdTCPServer and TIdTCPClient). The server should periodically issue a REPORT command to each client and receive a LOAD X response.&lt;br /&gt;
&lt;br /&gt;
I've set up the client app to create the TCPClient in a TThread descendant and after connecting to the server it just waits to receive a REPORT command, at which point the client answers with 'LOAD X', where X is an integer.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
repeat
  s := TCPClientInsideThread.IOHandler.ReadLn;
  if ( s = 'REPORT' ) then TCPClientInsideThread.IOHandler.WriteLn('LOAD ' + IntToStr(GetLoads.CPULoad));
until s = 'DISCONNECT';
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
On the server side, I don't know how to synchronize the server-client connection with the main thread and I don't know where to issue the REPORT command.&lt;br /&gt;
&lt;br /&gt;
I tried putting it in the OnExecute handler (using a relatively small timeout value to achieve repetition), but when more than one clients were connected, I started getting access violations.&lt;br /&gt;
I tried putting it in the OnTimer handler of a TTimer, where I cycled through each connection and sent a REPORT request, but that made the server hang after a few requests to even one client and then got access violations&lt;br /&gt;
&lt;br /&gt;
When and where should I issue the REPORT command on the server? How should I collect the response from the client? How do I put the response in the main thread of the server?&lt;br /&gt;
&lt;br /&gt;
Could someone please help out with ideas, if not code?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Thanks!</description>
      <pubDate>Wed, 13 May 2009 14:23:19 -0700</pubDate>
    </item>
  </channel>
</rss>