The Client on the other hand never sees the message...
...
if not IdTCPClient.IOHandler.InputBufferIsEmpty then
Always returns false.
That is because the
InputBuffer is filled with data only when a read operation is performed on the underlying socket, which
CheckForDataOnSource() does. Indy doesn't read from the socket until you tell Indy to read something. Most of the higher-level reading methods, like
ReadStream(), handle this internally for you, checking and filling the
InputBuffer until the requested data becomes available in full.
This seems to have solved it for now...
Typically, you don't need the
InputBufferIsEmpty() check, just call a reading method like
ReadStream() unconditionally and let it block the calling thread until the requested data arrives, eg:
procedure TLccEthernetClientThread.OnThreadComponentRun(Sender: TIdThreadComponent);
var
...
begin
ReceiveStreamConnectionThread.Size := 0;
idTCPClient.IOHandler.ReadStream(ReceiveStreamConnectionThread, DesiredSize);
...
end;
The
CheckForDataOnSource()/
InputBufferIsEmpty() approach is mainly used only when either:
- the calling thread does not want to be blocked and wants to do other things even when data is not available.
- the calling thread does not know how much data is being sent to it (as in your example).
In the latter case, unless you are writing a proxy or streaming media, not knowing how much data to read is generally a sign of bad protocol design.