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;