What's the best way to go about sending a TMemoryStream through Indy?
At the moment I'm trying:
procedure TClientForm.IdTCPClient1Connected(Sender: TObject);
begin
IdTCPClient1.IOHandler.Write(KStore.Size);
KStore.Position := 0;
IdTCPClient1.IOHandler.Write(KStore);
Memo1.Lines.Add('Client connected with server');
end
And at the Server end:
function MemoryStreamToString(M: TMemoryStream): string;
begin
SetString(Result, PChar(M.Memory), M.Size div SizeOf(Char));
end;
procedure TClientForm.IdTCPServer1Connect(AContext: TIdContext);
var
LStore: TMemoryStream;
Size: Int64;
LStore := TMemoryStream.Create;
LStore.Position := 0;
Size := AContext.Connection.IOHandler.ReadInt64();
AContext.Connection.IOHandler.ReadStream(LStore,Size);
end;
But despite a lack of errors, at the other end using that memory stream to string function just returns ???????????????????? in the text file I'm saving it to.