Hi guys!
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.
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.
[code]
repeat
s := TCPClientInsideThread.IOHandler.ReadLn;
if ( s = 'REPORT' ) then TCPClientInsideThread.IOHandler.WriteLn('LOAD ' + IntToStr(GetLoads.CPULoad));
until s = 'DISCONNECT';
[/code]
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.
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.
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
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?
Could someone please help out with ideas, if not code?
Thanks!