WSARecv Error :: Winsock

This is a discussion on WSARecv Error :: Winsock within the Windows Programming forums, part of the Platform Specific Boards category; Hi. I am in the debugging phase of a simple message program using Winsock API. The program has both server ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    WSARecv Error :: Winsock

    Hi.

    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;
    WSABUF bufferHDR,
    bufferDATA;
    char *header = new char[4], *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;
    }

    else
    {
    DetermineErrorWSARecv();
    receivedSize = bufferSize;
    }
    }

    UpdateAllViews(NULL);
    }

    else
    DetermineErrorWSARecv();

    delete [] data;
    delete [] header;
    }
    -----

    Have you experienced a similar problem?

    Thanks,
    Kuphryn
    Last edited by kuphryn; 05-15-2002 at 03:30 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. FIONREAD + WSARecv = Operation not supported (10054)
    By Tonto in forum Networking/Device Communication
    Replies: 9
    Last Post: 08-05-2006, 12:37 PM
  2. AcceptEx with WSASend and WSARecv :: Winsock
    By kuphryn in forum Networking/Device Communication
    Replies: 2
    Last Post: 10-05-2003, 09:48 PM
  3. WSARecv and IOCP :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 4
    Last Post: 12-26-2002, 09:19 PM
  4. WSASend & WSARecv :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-16-2002, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21