Re: How can I send a file through socket?
On May 31, 11:36 am, Water Lin <Water...@ymail.com> wrote:
Water Lin wrote:
I also need to ask another question.
When I read the file, I need to send it exactly the same as
the original one.
Are you sure? There are cases where this is true, but most
protocols have specific rules, and the file doesn't
necessisarily conform.
But if I use <ifstream> to read the file, the >> will stop at
a blankspace or newline.
So don't use >>.
Formally, there's no way in C++ to read a file literally.
Practically, if you open the file in binary mode and imbue the
"C" locale, you should be OK. (In theory, binary mode can
append any number of 0's to the end. In practice, I don't think
that this is a problem with any modern system.) And of course,
you have to do unformatted reads.
So, is it possible to read a whole file at one time without
any change?
If you have a big enough buffer. The usual solution is to read
fixed sized blocks, processing each block before reading the
next. (A professional program will usually use a pool of
buffers and non-blocking reads, but that requires some system
dependent code.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34