Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Feb : Re: Indy 9 TidTCPClient.WriteStream problem

www.cryer.info
Managed Newsgroup Archive

Re: Indy 9 TidTCPClient.WriteStream problem

Subject:Re: Indy 9 TidTCPClient.WriteStream problem
Posted by:"Tomislav Stamac" (tstam..@vip.hr)
Date:Thu, 28 Feb 2008 16:34:50

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.

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.

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;


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
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;


"Jamie Dale" <jamie.dale@yahoo.com> wrote in message
news:47c6b535@newsgroups.borland.com...
> What is the size of the file you are sending? - I've had a similar problem
> where sending small files seemed to be done instantly but the windows
> socket itself was still sending. This isn't an Indy fault (if this is what
> you are experiencing) but more one of windows.
>
> Again that is just one scenario but it does ring a bell with problems I've
> encountered in the past..
>
> JD
>
> "Tomislav Stamac" <tstamac@vip.hr> wrote in message
> news:47c6891a@newsgroups.borland.com...
>>
>> "Tomislav Stamac" <tstamac@vip.hr> wrote in message
>> news:47c672fd@newsgroups.borland.com...
>>> >
>>>> I suppose that I can copy internal Indy behaviour and send stream like
>>>> this:
>>>>
>>>> Size:=MyProgressStream.Size;
>>>> MyProgressStream.OnRead:=DoProgress;
>>>> Client.WriteInteger(Size);
>>>> Client.WriteBuffer(MyProgressStream.Memory^,size,true);
>>>>
>>>> Bit It's ugly :), there is Client.WriteStream to do that job.
>>>>
>>>>
>>>>
>>>
>>> No, that wouldn't work! :)
>>>
>>> MyProgressStream does not have public Memory property, and even if it
>>> does reading directly from memory^
>>> wouldn't trigger streams onread method.
>>>
>>> First of all I would have to copy my stream into a memorystream and pass
>>> that ones memory^ to indys writebuffer.
>>> Second I would then use Indys OnWork event.
>>>
>>
>> That's not working either, because TIdTCPClient.WriteBuffer ignores
>> TidTCPCliend.SendBufferSize. :(((
>>
>> Any other options?

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive