我正在逐包从套接字数据包中读取数据并写入另一个缓冲区以组合所有数据。
BOOL _ReadPacket(PBYTE BufferRead, DWORD &Length, SOCKET Socket)
{
WSABUF Buffer;
DWORD Flags = 0;
int Result = 0;
FILE *file;
Buffer.buf = (char *)BufferRead;
Buffer.len = Length;
Flags = 0;
Result = WSARecv(Socket, &Buffer, 1, &Length, &Flags, NULL, NULL);
// if ((file=fopen("D:/test/test1/test1.txt","a+") ) != NULL)
//{
//UINT val = Buffer.len;
//fprintf(file, "%d\n", val);
//
//fflush(file);
//fclose(file);
//}
return(Result != SOCKET_ERROR);
}
取消注释已注释的代码可解决问题。当我将代码注释掉时,为什么会得到损坏的数据?