When I send a file to the client, it becomes damaged and has a size in bytes above.
I have a version of this server running on Windows and it works fine, but I don't have the same result on Linux.
Can a file size on disk be a time error to send a size in bytes to a client that runs on a different platform?
the client side works fine, since I said that I have a version of this server running on Windows, the only difference in fread is: Size = fread(mfcc, 1, min(sizeof(mfcc), FileSize), fp);
is the fread function used correctly?
can an expert analyze and help find a mistake?
int Socket_Setup::FILE_UPLOAD(int iD, std::string DIR_UPLOAD)
{
char Block[1024];
long FileSize;
fp = fopen(DIR_UPLOAD.c_str(), "rb");
if (!fp)
{
errno_message.append((char*)strerror(errno));
FUNCTION_LOG(errno_message);
return 1;
}
fseek(fp, 0, SEEK_END);
FileSize = ftell(fp);
rewind(fp);
long Size_Send = htonl(FileSize);
Total = FileSize;
iResult = send(client[iD].socket, (const char*)&Size_Send, sizeof(long), 0);
if (iResult <= 0)
{
errno_message.append((char*)strerror(errno));
FUNCTION_LOG(errno_message);
return 1;
}
while (FileSize > 0)
{
BytesRead = fread(Block, 1, sizeof(Block), fp);
if (BytesRead <= 0)
{
errno_message.append((char*)strerror(errno));
FUNCTION_LOG(errno_message);
fclose(fp);
return 1;
}
if (send(client[iD].socket, Block, BytesRead, 0) != BytesRead)
{
errno_message.append((char*)strerror(errno));
FUNCTION_LOG(errno_message);
fclose(fp);
return 1;
}
FileSize -= BytesRead;
}
fclose(fp);
return 0;
}
source
share