Thread View: borland.public.cppbuilder.internet.socket
2 messages
2 total messages
Started by David
Thu, 07 Dec 2006 09:07
Indy 10: Send a file with TIdTCPClient
Author: David
Date: Thu, 07 Dec 2006 09:07
Date: Thu, 07 Dec 2006 09:07
26 lines
1463 bytes
1463 bytes
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
Author: Remy Lebeau (TeamB)
Date: Thu, 07 Dec 2006 10:34
Date: Thu, 07 Dec 2006 10:34
64 lines
2771 bytes
2771 bytes
"David" <microges@email.it> wrote in message
news:4577d9b5@newsgroups.borland.com...
> TCPClient.IOHandler.WriteLn(FileName);
You shouldn't be sending the full file path, only the file name:
TCPClient.IOHandler.WriteLn(ExtractFileName(FileName));
> TCPClient.IOHandler.WriteFile(FileName);
Try using Write(Stream) instead.
> FStream := TFileStream.Create(NomeFile, fmCreate, fmOpenWrite);
Where and how is NomeFile assigned?
> AContext.Connection.IOHandler.LargeStream := True;
Did you set LargeStream to True on the client side?
> 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads