我试图通过WinSock发送图像。我正在以固定大小的块读取图像。 WSASend()发送了适量的信息,但是当我收到它时,我的片段比常规块小。
char* TCPClient::ReadSocket()
{
Flags = 0;
if ((WSARecv(Info->GetSocket(), &(Info->GetWSABufForRead()), 1, &RecvBytes, &Flags, NULL, NULL)) == SOCKET_ERROR) {
if (WSAGetLastError() != WSAEWOULDBLOCK) {
sprintf(exceptBuf, "WSARecv() failed with error %d\n", WSAGetLastError());
throw new CException(exceptBuf);
}
else
{
printf("WSARecv() is OK!\n");
}
}
else {
if (RecvBytes == 0) {
return nullptr;
}
Info->SetRecvBytes(RecvBytes);
return Info->ReadBuffer();
}
return nullptr;
}
编辑:我真正想知道的是如何获取整个信息块。