I am using an IdTCPClient component to receive strings from my server.
Everything works fine, as long as the size of the string that
IdTCPClient needs to receive is small enough.
My server sends 3 strings,
'BEGINWORK'
aString
'ENDWORK'
The first 10 bytes of every string is always the length of the string.
if aString is larger then 8192 bytes, say 5000000 bytes, then the last
string 'ENDWORK' never arrives, nor the next string of 5000000 bytes...
The first arrives just fine.
Also, if I let the server send 1000000 times a string of just 20 bytes,
I only receive between 1200 and 1800 of these 20 bytes strings...
Here is the code for the client thread :
Maybe one of you can see what I am doing wrong here...
type
TReceiveThread = class(TThread)
private
intMessageCounter : integer;
strTemp : string;
StartTime : TTime;
StopTime : TTime;
procedure ToVCL;
protected
procedure Execute; override;
end;
procedure TReceiveThread.Execute;
var
intLength : integer;
begin
inherited;
while not ReceiveThread.Terminated do
try
if form1.IdTCPClient1.Connected then
begin
intLength := StrToInt(form1.IdTCPClient1.ReadString(10)); //
Read how long the string will be...
strTemp := form1.IdTCPClient1.ReadString(intLength); //
Read so many bytes from the string...
Synchronize(ToVCL);
end
else
ReceiveThread.Terminate;
except
on E:Exception do
begin
ShowMessage('Error := ' + E.Message + #13 + #13 + 'I will
disconnect now...');
form1.ButtonDisconnectClick(NIL);
end;
end;
end;
procedure TReceiveThread.ToVCL;
begin
if strTemp = 'BEGINWORK' then
begin
StartTime := Now;
intMessageCounter := 0;
end
else if strTemp = 'ENDWORK' then
begin
StopTime := Now;
form1.EditStartTime.Text := FormatDateTime('hh:mm:ss:zz',
StartTime);
form1.EditStopTime.Text := FormatDateTime('hh:mm:ss:zz',
StopTime);
form1.EditTotalTime.Text := FormatDateTime('hh:mm:ss:zz',
StopTime - StartTime);
end;
inc(intMessageCounter);
if form1.CheckBox1.Checked then
begin
form1.MemoReceivedData.Lines.Add(strTemp);
form1.MemoReceivedData.Lines.Add('end of message, Line := ' +
IntToStr(intMessageCounter) + ' Size := ' + IntToStr(Length(strTemp)) +
' bytes');
end;
end;
--
Guido Geurts
System Engineer
www.ADTechno.com
Guido....@adtechno.be
Tel : +32 (0)11 30 13 74
Never knock on Death's door. Ring his doorbell and run. (He hates
that.)
Also what version of indy are you using? Have you downloaded the latest?
Tony Caduto
"Guido Geurts" <Guido....@adtechno.be> wrote in message
news:3BDD7DFE...@adtechno.be...
We are building a socket engine that is capable of sending any string
from/to the server.
This engine will then be the base of all our client/server apps
True, 8K strings will not be send often, but our socket engine must be
prepared for anything...
Sending an 8K string is bye the way not the problem, I have succesfully
send 5MB strings with this aproach,
but not 2 after each other, it needs a little time in between to be able
to do that.
Also, sending more then 20000 strings of only 20 bytes each straight
after each other does not work, only between 1200 and 1800 arrive,
the rest is lost...
>
> Also what version of indy are you using? Have you downloaded the latest?
I have downloaded indy 9002, which was the latest version I could find.
udp ? Does idTCPClient uses udp so send packages ?
I did not know that, but it does explains a lot I guess...
No. TCP client uses TCP only.
--
Chad Z. Hower (Kudzu) - http://www.pbe.com/Kudzu/
Current Location: St. Petersburg, Russia
"Programming is an art form that fights back"