 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Tomas Guest
|
Posted: Tue Apr 20, 2004 11:37 pm Post subject: TidTCP and large files |
|
|
I can easily send small sized files with TidTCPClient/Server but when i
try to send 90-100MB files it's not sending. For example when i send
3-4MB sized files, OnWorkEnd event fires but with large files it never
fires. And after a while i see that it didn't transfer anything. Always
shows 0 KB. I'm using TidThreadComponent like this. Problem is only
with the large files.
procedure TForm1.FormCreate(Sender: TObject);
begin
strmRead := TFileStream.Create('C:uploadstest.zip', fmCreate);
strmWrite := TFileStream.Create('C:test.zip', fmOpenReadWrite);
end;
// strmWrite is a TFileStream
procedure TForm1.idThreadRun(Sender: TIdCustomThreadComponent);
begin
try
idClient.OpenWriteBuffer;
idClient.WriteStream(strmWrite);
idClient.CloseWriteBuffer;
finally
idClient.Disconnect;
end;
end;
// strmRead is a TFileStream
procedure TForm1.idServerExecute(AThread: TIdPeerThread);
begin
AThread.Connection.ReadStream(strmRead, -1, True);
end;
Regards,
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Apr 21, 2004 5:45 am Post subject: Re: TidTCP and large files |
|
|
"Tomas" <default (AT) default (DOT) com> wrote
| Quote: | idClient.OpenWriteBuffer;
idClient.WriteStream(strmWrite);
idClient.CloseWriteBuffer;
|
*DO NOT* use that kind of write buffering with large amounts of data!!! You
did not specify any kind of threshold when calling OpenWriteBuffer(), so
WriteStream() is just going to buffer the entire stream into memory in its
entirety before finally sending the buffered data. For a large file, you
aren't seeing anything transfered because nothing is going to be transferred
to begin with until the entire stream is loaded into memory, which is going
to take awhile (if successful at all). WriteStream() is going to just kept
dumping the stream data into more and more memory without actually sending
anything at all. Get rid of the write buffering altogether, its not doing
you a bit of good at all. In fact, 99.999999% of the time, you never need
to use write buffering at all and should avoid it.
Change your sending code to simply this instead:
procedure TForm1.idThreadRun(Sender: TIdCustomThreadComponent);
begin
try
idClient.WriteStream(strmWrite);
finally
idClient.Disconnect;
end;
end;
Gambit
|
|
| Back to top |
|
 |
Tomas Guest
|
Posted: Wed Apr 21, 2004 10:15 pm Post subject: Re: TidTCP and large files |
|
|
Thank you, it works perfect now. I used OpenWriteBuffer and
CloseWriteBuffer without to know any details about their usage. After
you explanation, now i know what they are really using for.
Thank you for your usefull answers again.
Cheers,
Remy Lebeau (TeamB) wrote:
| Quote: |
"Tomas" <default (AT) default (DOT) com> wrote in message
news:4085b430 (AT) newsgroups (DOT) borland.com...
idClient.OpenWriteBuffer;
idClient.WriteStream(strmWrite);
idClient.CloseWriteBuffer;
*DO NOT* use that kind of write buffering with large amounts of
data!!! You did not specify any kind of threshold when calling
OpenWriteBuffer(), so WriteStream() is just going to buffer the
entire stream into memory in its entirety before finally sending the
buffered data. For a large file, you aren't seeing anything
transfered because nothing is going to be transferred to begin with
until the entire stream is loaded into memory, which is going to take
awhile (if successful at all). WriteStream() is going to just kept
dumping the stream data into more and more memory without actually
sending anything at all. Get rid of the write buffering altogether,
its not doing you a bit of good at all. In fact, 99.999999% of the
time, you never need to use write buffering at all and should avoid
it.
Change your sending code to simply this instead:
procedure TForm1.idThreadRun(Sender: TIdCustomThreadComponent);
begin
try
idClient.WriteStream(strmWrite);
finally
idClient.Disconnect;
end;
end;
Gambit
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|