EDIT: I got the filesize in bytes using filesize. Now i can send that info too, but how i could clear that specified number of bytes from inputbuffer?
Thanks you a lot for your long reply.
You should include the file's size, too.
I have no idea how to get the filesize. Anyway, the TCP connection is always open until one of the parts (server/client) close it. (using regular pings client/server)
I would not send the hash up front, though.
99% of times, the file hash is already stored on memory (files are hashed inmediately after been created). Also, the hash is the main information to let know the receiver if it is the required file.
I would also suggest making the receiver send a preliminary response back to the sender BEFORE allowing the sender to begin sending the actual file bytes.
It is been done before (almost always):
Receiver: REQUEST {filename} {filehash}
sender: FILE {filename} {filehash}
But sometimes the sender generates a new file that must be shared with all the peers in the network. In those cases, the sender sends this:
sender: FILE {filename} {filehash} {UserWhoCreatedThefile} {SignToVerify}
The receiver, in this case, should verify if {UserWhoCreatedThefile} and {SignToVerify} are valid. If so, then download the file and re-send to the other peers; if not, just ignore the file.
So the receiver is doing this:
LLine := AContext.Connection.IOHandler.ReadLn(IndyTextEncoding_UTF8);
// verify is {UserWhoCreatedThefile} {SignToVerify} is valid
if Validated then
begin
AFileStream := TFileStream.Create(UpdateZipName, fmCreate);
AContext.Connection.IOHandler.ReadStream(AFileStream);
AFileStream.Free;
end
else
begin
// discard it; how??
end;
For your reply, i guess i could send the filesize in advance (even when i do not know how to get that info) so, if the receiver do not want to receive the file, it could clear that size from the inputbuffer (what i neither know how could be done) without affect the other incoming information.
Againn, thank you for your help