0

I’m setting up a new monitoring program and I want to add a watchdog program to none main thread program to control net dead state. Sometimes, when I waiting to receive data from the server and occurs a net problem, my code looked at this line and can not do any things. I use timeout and keepalives mechanism but in some case, it's not useful and can not solve the problem. How can I implement some code to do this? This is my sample code:

  //after sending data, wait to receive ack answer from the server, the server 
    response by short integer ack sing followed by an integer packet id.
   In_buffer:= nil; 
 try
   with IdTCPClient1.IOHandler do
         begin
           if CheckForDataOnSource(5000) then  {my program block here!!!!!!!!
                                                 ,In special(dead connection) 
                                                 network problem, and can not 
                                                 get control back}
              begin
                 if not InputBufferIsEmpty then
                    begin
                       InputBuffer.ExtractToBytes(In_buffer);//use data
                    end
                 else
                    begin
                     //empty buffer                               
                       SendsState(3,2,deny_timeout);//send state to main thread                  
                    end;
              end
            else
               begin
                //timeout or other
                   SendsState(3,2,deny_timeout);//send state to main thread
            end;
     end;
  except on e : Exception do
     begin
        SendsState(3,2,deny_exception);   //send state to main thread
        raise;
     end;
  end;
  • 1
    Please provide the code showing what you've got so far. – constt Aug 22 '19 at 07:07
  • Why exactly don't timeouts work for you? That would be the "natural" solution, rather than having an external mechanism, which would need to know which threads wait on network I/O. – Robert Aug 22 '19 at 12:51
  • Thanks, I add some code to the question, that is used in my program. – R_D Safatco Aug 23 '19 at 10:19

0 Answers0