Answer the question
In order to leave comments, you need to log in
Why does the WinSock receive buffer fill up with garbage?
Hello.
Sources taken from MSDN:
do {
iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
if (iResult > 0) {
iSendResult = send(ClientSocket, recvbuf, iResult, 0);
if(iSendResult==SOCKET_ERROR){
printf("send failed with error: %d\n", WSAGetLastError());
closesocket(ClientSocket);
WSACleanup();
}
for (int i = 0; i < iResult; i++) {
std::cout << recvbuf[i];
}
}
else if (iResult == 0) {
//std::cout << "Connection closing...\n";
std::cout << std::endl;
}
else {
printf("recv failed with error: %d\n", WSAGetLastError());
closesocket(ClientSocket);
WSACleanup();
std::cout << "Error in receive\n";
}
} while (iResult > 0);
Answer the question
In order to leave comments, you need to log in
And if I look at strlen(recvbuf), I get 16. Where does such a tail come from?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question