Here is the complete onExecute Event Handler. I have no onConnect or onDisconnect Event handlers. I have just spotted that if the creation of the Stringlist fails with an exception, the context would not get disconnected. I may change this to use 2 try finally sections.
The various response methods contain some complicated code but they make use of tidnotify and threadsafestringlists.
What I cant understand is why I don't get the problem here even when I configure our software with the exact same settings and use the same hardware to send the XML.
There are also many customers using this successfully with as many as 50-60 terminals communicating fine and no deadlocks. The 2 systems which experience these issues are only responding to 2 terminals. We have power cycled the terminals and also put the latest firmware in them etc..... not sure if its the code now, but i cant see any other explanation for the apparent deadlock.
procedure TCustomXMLServer.TCPServerExecute(aContext: TIdContext);
// MAIN sever execution routine. Called when stuff comes in.
var
RequestStr: string;
inList : TStringList;
begin
with aContext.Connection.IOHandler do
try
inList := TStringList.Create;
try
ReadTimeout := TimeOut;
WriteLn ('<srv><connect>ELF Comms Server</connect></srv>');
repeat
RequestStr := ReadLn(EOL);
if RequestStr <> '' then
InList.add(RequestStr);
if Pos('</interface>' , RequestStr) > 0 then
Break;
// Read all the message data into the InList string list.
until (readLnTimedout);
{if READER_SHOW_DEBUG then
DisplayStrings(InList);}
// Check for a heartbeat.
if TElfUtils.IsSubStrInString('<heartbeat>', inList.Text)then
HeartBeatResp(aContext.Connection.IOHandler, inList.Text)
// Check for a enquiry.
else if TElfUtils.IsSubStrInString('<enq>', inList.Text)then
EnquiryResp(aContext.Connection.IOHandler, inList.Text)
// Check for an transaction.
else if TElfUtils.IsSubStrInString('<trans>', inList.Text) then
TransResp(aContext.Connection.IOHandler, inList.Text)
// Check for an validation request.
else if TElfUtils.IsSubStrInString('<val>', inList.Text) then
ValidationResp(aContext.Connection.IOHandler, inList.Text)
// Check for download request
else if TElfUtils.IsSubStrInString('<requestDownload>', inList.Text) then
DownloadResp(aContext.Connection.IOHandler, inList.Text)
//Reciving File From device NEW!
else if TElfUtils.IsSubStrInString('<uploadFile>', inList.Text) then
UploadResp(aContext.Connection.IOHandler, inList.Text)
// Check for download request NEW!
else if TElfUtils.IsSubStrInString('<requestDownloadFile>', inList.Text) then
DownloadResp(aContext.Connection.IOHandler, inList.Text);
finally
inList.Free;
aContext.Connection.Disconnect;
end;
except
on E:Exception do
begin
if not (e is EIdSilentException) then
TXMLTraceNotify.XMLTrace('TCPServerExecute: ' + E.Message, ttProblem, FTraceProc);
raise; //we must raise all exceptions for indy to handle them.
end;
end;
end;