I have a client application that should send notify messages to an optional server application. The client should not be influenced by whether the server appliction exists or not. It should try to connect to the server application and send the notify message and in case of errors it should just silently ignore all errors and continue work.
I'm using Indy for the TCP communication but all attempts to avoid error messages showing up (i.e. when ther server application closes while connected to the client) failed.
Is there a way to really make this robust?
Current code looks like this:
if (not Client.Connected) then
begin
Client.Host := ServerName;
Client.Port := ServerPort;
Client.ConnectTimeout := ConnectTimeout;
try
Client.Connect;
except
Exit;
end;
end
try
Client.IOHandler.WriteLn ('NOTIFYCHANGE "' + Param + '"');
Client.IOHandler.WriteBufferFlush;
except
try
Client.Disconnect;
except
{ ignore errors while disconnecting }
end;
try
Client.Connect;
except
{ ignore errors while connecting }
end;
end;