BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TidTCP and large files

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock
View previous topic :: View next topic  
Author Message
Tomas
Guest





PostPosted: Tue Apr 20, 2004 11:37 pm    Post subject: TidTCP and large files Reply with quote



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





PostPosted: Wed Apr 21, 2004 5:45 am    Post subject: Re: TidTCP and large files Reply with quote




"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





PostPosted: Wed Apr 21, 2004 10:15 pm    Post subject: Re: TidTCP and large files Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.