I need to know how to use Indy 10 to send and receive a file with TCP. I have some old examples from Indy 9, but I cant get them to work in Delphi 2006 and Indy 10.
-------------
Please note
-------------
If you are using later versions of Indy 10 than what ships, TIdStreamVSL was replaced with just TIDStream
uses IDStream, IdSyncObjs (might be IdSync, can't check right now)
and it's something like :-
var
AStream: TIdStream
begin
AStream := TIdFileStreamCreate(....
Let me know if you're using a later version and I'll look up the commands at work later on
What I tend to do is send the filename, the filesize, and then the file
That way, the server knows what to call the file, and how big it is supposed to be
for later versions of Indy 10 (which the Indy team recommend), you would do :-
--client
uses
IdObjs, IdSys;
var
AStream: TIDStream;
begin
TCPClient1.Connect;
TCPClient1.IOHandler.LargeStream := True; // fully support large streams
procedure TfServerMain.IdTCPServer1Connect(AContext: TIdContext);
begin
AContext.Connection.IOHandler.LargeStream := True;
end;
procedure TfServerMain.IdTCPServer1Execute(AContext: TIdContext);
var
InCmd: string;
AStream: TIdStream;
S: string;
FileSize: Int64;
Filename: string;
begin
InCmd := ReceiveStringWithLogging(AContext);
if InCmd = 'FILE' then
begin
//followed by separate FILENAME, then FILESIZE, then the actual STREAM
Filename := ReceiveStringWithLogging(AContext);
S := ReceiveStringWithLogging(AContext); // filesize
FileSize := StrToInt(S);
ForceDirectories(ExtractFilePath(Paramstr(0)) + 'In');
AStream := TIDFileStream.Create(ExtractFilePath(Paramstr(0)) + 'In\' + Filename, fmCreate);
try
AContext.Connection.IOHandler.ReadStream(AStream, Filesize, False);
finally
FreeAndNil(AStream);
end;
end;
end;
0
TomasThilAuthor Commented:
Thanks, been looking for a solution the last 4 days. Only one thing if some one else read this.
To get this to work the client code have to be changed from :
Filename := ReceiveStringWithLogging(A
S := ReceiveStringWithLogging(A
with
Filename := AContext.Connection.IOHand
S := AContext.Connection.IOHand