Could not transfer file using socket. Rather, the file is transmitted, but always of a different size. Here is the code snippet to send:
FILE *inFile = fopen(this->FullDir, "r+b"); //FILE *outFile = fopen(this->DeskDir, "w+b"); if (inFile != 0) { char* buffer[16384]; //выделяем блок 16Кб while (!feof(inFile)) //пока не конец файла { fread(buffer, 1, sizeof(buffer), inFile); //копируем блок send(s, (char*)&buffer, sizeof(buffer), 0);//передаём блок } }
And for reception, respectively:
do { msg_len = recv(new_client_socket, (char*)&buffer, MAX_MESSAGE_LENGTH, 0); fwrite(buffer, 1, sizeof(buffer), output); } while (msg_len > 0);
The file size is 2.50 MB, it always comes in different ways from 1 MB to 2.2 MB. Where is the error?