Your code is already sending the file size. You are setting the AWriteByteCount
parameter of Write(TStream)
to True, which tells it to send the stream size before sending the stream data. And you are telling ReadStream()
to read the stream size before reading the stream data. So Indy is already validating the size for you before ReadStream()
exits. You don't need to do it manually at all.
Send Files with TCP from client to server knowing file size Delphi
سؤال
Hello im trying to send a file Via TCP with delphi using Indy Components with a Client/Server
i manage to send and recieve the files correctly, the problem is before sending the file i would like to send its size aswell to compare it after i get it the server.
Now im sending the files from the Client To Server.
Client:
Ms := TMemoryStream.Create;
Ms.LoadFromFile('cliente.exe');
Ms.Position := 0;
Result := True;
Client.IOHandler.LargeStream := True;
try
Client.IOHandler.Write(ms, 0, True);// (Ms, 0, true);
except
Result := False;
end;
Ms.Free;
Server:
AStream := TFileStream.Create('C:\temp\file.exe', fmCreate + fmShareDenyNone);
try
AContext.Connection.IOHandler.LargeStream := True;
AContext.Connection.IOHandler.ReadStream(AStream, -1,false);
finally
FreeAndNil(AStream);
Memo1.Lines.Add('File received');
end;
So the question would be how could i send the file size with the file?
المحلول
لا تنتمي إلى StackOverflow