Board index » cppbuilder » Indy 10: Send a file with TIdTCPClient

Indy 10: Send a file with TIdTCPClient


2006-12-07 05:06:46 PM
cppbuilder102
I have a little proble when try to send a file with component TIdTCPClient.
My procedure is:
Client unit:
TCPClient.IOHandler.WriteLn(FileName);
TCPClient.IOHandler.WriteFile(FileName);
Server unit:
FStream := TFileStream.Create(NomeFile, fmCreate, fmOpenWrite);
AContext.Connection.IOHandler.LargeStream := True;
AContext.Connection.IOHandler.ReadStream(FStream);
FreeAndNil(FStream);
The problem is the error "Socket Error 10053" when the WriteFile
function is executed.
Someone have some idea to solve this? (Or some example)
Thanks,
David
Ps. Sorry for my English - I'm Italian
 
 

Re:Indy 10: Send a file with TIdTCPClient

have a little proble when try to send a file with component TIdTCPClient.
My procedure is:
Client unit:
TCPClient.IOHandler.WriteLn(FileName);
TCPClient.IOHandler.WriteFile(FileName);
Server unit:
FStream := TFileStream.Create(NomeFile, fmCreate, fmOpenWrite);
AContext.Connection.IOHandler.LargeStream := True;
AContext.Connection.IOHandler.ReadStream(FStream);
FreeAndNil(FStream);
The problem is the error "Socket Error 10053" when the WriteFile
function is executed.
Someone have some idea to solve this? (Or some example)
Thanks,
David
Ps. Sorry for my English - I'm Italian
 

Re:Indy 10: Send a file with TIdTCPClient

"David" < XXXX@XXXXX.COM >wrote in message
Quote
TCPClient.IOHandler.WriteLn(FileName);
You shouldn't be sending the full file path, only the file name:
TCPClient.IOHandler.WriteLn(ExtractFileName(FileName));
Quote
TCPClient.IOHandler.WriteFile(FileName);
Try using Write(Stream) instead.
Quote
FStream := TFileStream.Create(NomeFile, fmCreate, fmOpenWrite);
Where and how is NomeFile assigned?
Quote
AContext.Connection.IOHandler.LargeStream := True;
Did you set LargeStream to True on the client side?
Quote
AContext.Connection.IOHandler.ReadStream(FStream);
By default, ReadStream() reads an integer value (an Int64 in this case
because you set LargeStream to True) specifying the number of stream bytes
being sent. However, WriteFile() does not send that value. So you are
corrupting your file transfer. If you are going to use ReadStream() like
that, then you have to call Write(Stream) on the client side instead of
WriteFile(). For example:
--- Client ---
uses
IdGlobal, IdObjs, IdSys;
var
Stream: TIdStream;
begin
Stream := TIdReadFileExclusiveStream.Create(FileName);
try
TCPClient.IOHandler.WriteLn(ExtractFileName(FileName));
TCPClient.IOHandler.LargeStream := True;
TCPClient.IOHandler.WriteStream(Stream, 0, True);
finally
Sys.FreeAndNil(Stream);
end;
end;
--- Server ---
NomeFile := 'C:\Some Folder\' +
ExtractFileName(AContext.Connection.IOHandler.ReadLn);
FStream := TIdFileCreateStream.Create(NomeFile);
try
AContext.Connection.IOHandler.LargeStream := True;
AContext.Connection.IOHandler.ReadStream(FStream);
finally
Sys.FreeAndNil(FStream);
end;
Gambit
 

{smallsort}

Re:Indy 10: Send a file with TIdTCPClient

"David" < XXXX@XXXXX.COM >wrote in message
Quote
TCPClient.IOHandler.WriteLn(FileName);
You shouldn't be sending the full file path, only the file name:
TCPClient.IOHandler.WriteLn(ExtractFileName(FileName));
Quote
TCPClient.IOHandler.WriteFile(FileName);
Try using Write(Stream) instead.
Quote
FStream := TFileStream.Create(NomeFile, fmCreate, fmOpenWrite);
Where and how is NomeFile assigned?
Quote
AContext.Connection.IOHandler.LargeStream := True;
Did you set LargeStream to True on the client side?
Quote
AContext.Connection.IOHandler.ReadStream(FStream);
By default, ReadStream() reads an integer value (an Int64 in this case
because you set LargeStream to True) specifying the number of stream bytes
being sent. However, WriteFile() does not send that value. So you are
corrupting your file transfer. If you are going to use ReadStream() like
that, then you have to call Write(Stream) on the client side instead of
WriteFile(). For example:
--- Client ---
uses
IdGlobal, IdObjs, IdSys;
var
Stream: TIdStream;
begin
Stream := TIdReadFileExclusiveStream.Create(FileName);
try
TCPClient.IOHandler.WriteLn(ExtractFileName(FileName));
TCPClient.IOHandler.LargeStream := True;
TCPClient.IOHandler.WriteStream(Stream, 0, True);
finally
Sys.FreeAndNil(Stream);
end;
end;
--- Server ---
NomeFile := 'C:\Some Folder\' +
ExtractFileName(AContext.Connection.IOHandler.ReadLn);
FStream := TIdFileCreateStream.Create(NomeFile);
try
AContext.Connection.IOHandler.LargeStream := True;
AContext.Connection.IOHandler.ReadStream(FStream);
finally
Sys.FreeAndNil(FStream);
end;
Gambit