I am in the debugging phase of a simple message program using Winsock API. The program has both server and client features. The user can choose to be a server or a client. Anyways, everything works including server start, stop, accept client, and send data. However, I am having problems receiving data. WSARecv fail with the error WSAEFAULT.
// WSAEFAULT: "Bad address"
I have tested both sides. I get the same error no when I try to receive data from the server end and from the client end. Again, sending the data works fine, its just that I cannot receive the data.
Here is the function to read the data.
if (socket != INVALID_SOCKET)
DWORD bufferSize = 0, receivedSize = 0;
char *header = new char, *data;
bufferHDR.len = 4;
bufferHDR.buf = header;
// The program never makes it pass this point
if (WSARecv(socket, &bufferHDR, 1, &receivedSize, 0, 0, 0) == 0)
bufferSize = static_cast<DWORD>(*bufferHDR.buf);
data = new char[bufferSize];
bufferDATA.len = bufferSize;
bufferDATA.buf = data;
receivedSize = 0;
DWORD bufferProgress = 0;
while (receivedSize < bufferSize)
if (WSARecv(socket, &bufferDATA, 1, &bufferProgress, 0, 0, 0) == 0)
newData += bufferDATA.buf;
receivedSize += bufferProgress;
receivedSize = bufferSize;
delete  data;
delete  header;
Have you experienced a similar problem?