A
A
Alex Serov2016-12-06 03:33:55
Data transfer
Alex Serov, 2016-12-06 03:33:55

How to transfer a file of unknown size?

How will the receiving party understand that the end of the file has come?
How can you mark it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rou1997, 2016-12-06
@gibsonman01

You can mark with markers (boundaries), according to the EOF principle, but then you will have to read byte by byte until the cycle reaches the marker, it’s better otherwise - pass the file size in bytes in the header, and then the file itself, but then you need to take care of security, since there are bots on the Internet and their "visit" to the server is much more likely than you think, why "come" to a random IP and not a random port 80 at all remains a mystery, but bots have their own logic, which means you need to protect yourself from "left" packets that will have arbitrary instead of a header bytes and reading them will "clog" the RAM on the server and in any case the server will crash with an error.
You can look at implementations of HTTP, FTP.

A
anikavoi, 2016-12-06
@anikavoi

When transferring the file file.dat, we write the contents during the transfer to file.tmp, and when everything has already been transferred, we rename it to file.dat. Thus, the desired file appears only when everything has already been transferred.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question