Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Dec : Re: idTcpClient and Streams
| Subject: | Re: idTcpClient and Streams |
| Posted by: | "Kendrick" (kkendri..@harbornet.com) |
| Date: | Wed, 5 Dec 2007 14:46:25 |
Remy-
Yes I am sure I am doing it all wrong - here are some snippets
#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
#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
#3 Server sends the stream
TIdContext(Cnncts[p]).Connection.IOHandler.WriteBufferOpen;
TIdContext(Cnncts[p]).Connection.IOHandler.Write(aStream);
// A read Timeout error is rasied. Continuing hits a breakpoint to load the
xml stream into the memo in #4
#4 Client gets the stream in OnWorkEnd
if ReadingBuffer and (aStream.Size = sizeOfServerStream) then //I don't
think the second test is valid.Always equal values
try
Memo1.Lines.LoadFromStream(aStream); //This blanks out the Memo
cds1.LoadFromStream(aStream); //cds1 is a clientdataset;
try
cds1.Active:= True;
except
Memo1.Lines.Add('exception Saving stream');
end;
except
Memo1.Lines.Add('exception Reading stream');
end;
Thanks - Kevin