Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Feb : Re: Indy 9 TidTCPClient.WriteStream problem
| Subject: | Re: Indy 9 TidTCPClient.WriteStream problem |
| Posted by: | "Jamie Dale" (jamie.da..@yahoo.com) |
| Date: | Thu, 28 Feb 2008 22:48:54 |
"Tomislav Stamac" <tstamac@vip.hr> wrote in message
news:47c6d49b@newsgroups.borland.com...
> Hi.
>
> Yes, Stream is reset before sending.
> Size is 20-120 kb it depends.
>
> You had a problem because Your file was smaller than SendBufferSize.
> Once You decreased SendBufferSize to smaller value, You solved Your
> problem I suppose.
No that isn't what happened - Don't assume anything - you don't even know
what I was working on...
> This problem is different. It was working well in Indy 8.
> Something has changed in internal implementation in Indy 9, and OnWork
> event is never called for WriteStream.
> My SendBufferSize is 1024 bytes, and streamsize is about 50 kBytes, so
> OnWork event should be called about 50 times.
Yep, sounds correct..
>
> Anyway I solved the problem, but I still think It's ugly :-D
>
> Sollution is like this:
>
> var
> MyProgresStream:TFileProgressStream;
> begin
> MyProgresStream.LoadFromFile('SomeJPG.JPG');
> MyProgresStream.OnRead:=OnStreamRead;
> Client.WriteStream(MyProgressStream,True,True);
> end;
Yep, certainly ugly..
> procedure TfrmClient1.OnStreamRead(Sender: TObject; Count:integer);
> var
> MSecs:Cardinal;
> Secs:word;
> BytesPerSec:word;
> begin
> BytesPerSec:=0;
> TrProgress:=FileStream.Position;
> MSecs:=GetTickCount-StartTransfer;
> Secs:=MSecs div 1000;
> if Secs<>0 then BytesPerSec:=TrProgress div Secs;
> LbSpeed.Caption:=IntToStr(BytesPerSec)+' Byte/s';
> ggProgress.Progress:=TrProgress;
> // self.Update;
> Client.FlushWriteBuffer(); <------------THIS HELPED
> AND
Gotcha. I was using WriteBuffering too until Remy put me straight on it. I'd
totally forgotten about this until reading your reply and seeing this line.
Do not use WriteBuffering as it doesn't seem to make OnWork...Work. It just
seems to absorb the entire file elsewhere within windows and gives the
impression that the entire file has been sent instantly.
You don't need to use ProcessMessages...
> FORCED INDY TO
> Application.ProcessMessages; WRITE TO SOCKET AT THE MOMENT IT
> WAS READ FROM STREAM
> // Timer1Timer(nil);
> // DEBUG
> if SwRazvojniStroj then sleep(50);
> end;