Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Nov : tidTCPClient/Server - problem transfering data.
| Subject: | tidTCPClient/Server - problem transfering data. |
| Posted by: | "Arvid Haugen" (arv..@elis.no) |
| Date: | Tue, 20 Nov 2007 18:16:35 |
Hi,
I am using Delphi 2006 and Indy 10.
We are using TidTCPServer and TidTCPClient. We can not rewrite this to
TidCmdTCPServer and TidCmdTCPClient!!!
On the client side we the code looks like this:
result := IdTCPClient1.SendCmd('100 Test', [201, 202]);
if result = 201 then
begin
while not IdTCPClient1.IOHandler.InputBufferIsEmpty do
begin
lline := IdTCPClient1.IOHandler.ReadLn;
"processing of lline".
end;
end
else
...
On the server side we have a code like this:
procedure TForm5.IdTCPServer1Execute(AContext: TIdContext);
var
lline: String;
begin
lline:= AContext.Connection.IOHandler.ReadLn;
if trim(lline) = '' then
AContext.Connection.IOHandler.WriteLn('')
else
begin
AContext.Connection.IOHandler.Write(Memo1.lines);
end;
end;
This works just fin 99% of the time - but now and then the client does not
receive all data from the server.
For testing I code a "end of message string", that I put at the end on the
TStringList (Memo1.lines) written in the server, and modified the loop on
the client side to wait for the "end of message string". This works find -
but now and then it still does not get all data. I coded a 5 second delay to
prevent a neverending loop. This times out.
For both cases the data is there next time I try to write something from the
client. That means that the sendcmd will fail since it gets som rubish data
left from last session instead the expected command result.
Anyone seen this problem??? The server/client can handle thousands of
commands, but then suddenly it fails. The messages that are not transfered
can actually be smaller than messages transferred... I can not find any
special about the messages that fail...
Should I use some kind of flush command to ensure that everything is
written??? That's the only thing I can think of...