I am writing a program for transferring files between different clients and i have a little problem.
I ran to an example where it doesn't work.
I have a pdf file and i am reading it using fread
:
bytes = fread(chunk, 1, BUFLEN - 1, from_file);
After a bit of debugging i found out that this line of code does not read BUFLEN - 1
bytes (oh by the way, the file is big and i am iterating only once to take the first BUFLEN - 1
bytes, so the file has more than BUFLEN - 1
bytes). The return value of fread
is actually BUFLEN - 1
, but after writing this chunk to a file it has a much smaller size.
I suppose fread
stops reading when running into something, but i couldn't find out what.
I opened the file with "rb"
so this isn't the problem either. Moreover, my program seems to read well any text files, of any size, and this is the reason i believe it has some problems when finding different type of bytes.
EDIT: I am sending the chunk via
send(socksv, chunk, strlen(chunk), 0);
In receive:
n = recv(i, chunk, BUFLEN - 1, 0);
After that i write it like this
fwrite(chunk, 1, strlen(chunk), copy_file);