Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Dec : Re: idTcpClient and Streams
| Subject: | Re: idTcpClient and Streams |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Wed, 5 Dec 2007 15:51:04 |
"Kendrick" <kkendrick@harbornet.com> wrote in message
news:47572a37$1@newsgroups.borland.com...
> Yes I am sure I am doing it all wrong - here are some snippets
You did not show enough code to fully diagnose your problem.
> #1 Server preps stream and sends size to client
> aStream:= TMemoryStream.Create;
> cds1.SaveToStream(aStream,dfBinary); // dfBinary, dfXML, dfXMLUTF8
> SendClientMessage(aMsg, IntToStr(aStream.Size), False, True); //aMsg
> has the IP address and client's thread handle
What does SendClientMessage() actually do?
> #2 Client builds request Command and sends to server:
> tcp1.IOHandler.WriteLn('SENDDATA');
> //aStream.Seek(0,0);
> tcp1.IOHandler.ReadStream(aStream, (sizeOfServerStream)); //aStream is
> TMemoryStream
Where are you sending the original command that caused the server to prepare
the data? Where are you reading that response to get the stream size? For
that matter, why are you using separate commands to prepare the data and
then receive it afterwards?
> #3 Server sends the stream
> TIdContext(Cnncts[p]).Connection.IOHandler.WriteBufferOpen;
> TIdContext(Cnncts[p]).Connection.IOHandler.Write(aStream);
Are you ever calling WriteBufferClose()?
I do not recommend using write buffering with streams. Especially when
large streams are involved. That wastes memory, and can cause socket errors
anyway.
> #4 Client gets the stream in OnWorkEnd
Why are you loading the data from inside of OnWorkEnd instead of after
ReadStream() exits?
> Memo1.Lines.LoadFromStream(aStream); //This blanks out the Memo
You are not seeking the stream's Position back to 0 after receiving the data
before then loading it into the Memo.
> cds1.LoadFromStream(aStream); //cds1 is a clientdataset;
Likewise, you are not seeing the Stream Position back to 0 after the Memo
was loaded from it.
Gambit