Delphi XE2, Indy V10, Windows 7 Pro – but I think I have a general conceptual problem.
- Indy’s TCP client is synchronous – it uses blocking calls.
- However parts of my application are asynchronous – I want to send data over TCP and wait for a response when
A) the 3rd party serial port component reports input from the serial port (it appears to be asynchronous & run in it’s own thread, posting messages to my application’s main form’s Windows message queue) and
B) when one of several timers expires (also asynchronous) -
My application’s handling of these async events needs to make a blocking call to send data over TCP and get a response before the next TCP data can be sent. E.G.
procedure OnSerialPortRxChar(...); begin if SendTCpData(...) = 'OK' then ... end; procedure OnTimerExpiry(...); begin if SendTCpData(...) = 'OK' then ... end;
These should not interrupt each other, but currently do.
Obviously, my function SendTCpData needs some sort of blocking mechanism to prevent reentrant calls, or a queuing mechanism. Given that the caller needs to know the result, is my best solution a mutex? The problem is that the TCP transaction is just one line in the 20 line SendTCpData function which those asynch events can invoke.
I hope that I have explained this comprehendably. If not, please request more information.
Thank you very much in advance for your help.
You can use TIdAntiFreeze. Just drop it on your main form. Your call will still be blocked but your GUI will not be blocked. You may want to use some timeouts with your client though.