Thread: Calling WSASend() Consecutively :: Winsock

  1. #1
    Registered User
    Join Date
    Nov 2001

    Calling WSASend() Consecutively :: Winsock

    Okay. I have determine one major problem, or should I say characteristic of WSASend and/or WSARecv.

    For some reason, I cannot call WSASend one after another. For example, let say I call WSASend to send a 4 byte buffer to the client indicating the size of the incoming data. That works find and the client receives the first WSASend package without problems. However, for some reason I cannot call WSASend the second time to send the actual package. The error on the *sending* side is WSAEFAULT:

    // WSAEFAULT: "Bad address"

    The error on the *receiving* side is WSAEWOULDBLOCK:

    // WSAEWOULDBLOCK: "Resource temporarily unavailable"

    The bottomline is I cannot send two data buffer consecutively. I am using the WSAAsyncSelect I/O Mode. Is there a specific specification that I missed as far as sending and receiving?

    Please message me if you have any ideas.


  2. #2
    train spotter
    Join Date
    Aug 2001
    near a computer
    the WOULDBLOCK probably means there is no data to be read.
    (you calling the recv in response to a getting a FD_READ msg? )

    the address error could be caused by exceeding the max msg size or not supplying the right buffer sizes
    and check, use setsockopt() to increase the buffer size.

    or could be
    send(iSocket,sBuffer,sizeof(sBuffer),FLAGS);//mem size is not the msg size

    instead of

    send(iSocket,sBuffer,strlen(sBuffer),FLAGS);//string len is the msg len
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Nov 2001

    I am developing the program under WindowsXP and Athlon 750mhz.

    I am very, very close to getting everything working as planned. Here is where my progress. The program sends data perfectly (I believe). For example:

    // Given WSABUF dataHDR, dataMessage

    - send header buffer (dataHDR.Buf = data size)
    - send data buffer (dataMessage.Buf = message)

    // Given WSABUF inHDR, inMessage

    - receive header buffer (inHDR = data size)
    - use atol() to convert inHDR.Buf into an integer data size
    - receive data buffer (inMessage.Buf = message)

    Okay. I checked the actual receive size after calling WSARecv for the data buffer. The receive size is accurate, i.e. it received the exact number of byte that was sent. However, I cannot extract all characters from inMessage.Buf.

    I use this code to extract the characters from inMessage.Buf

    // CString message;
    // message += *inMessage.Buf

    The problem is the code above only extracts the *first* character in inMessage.Buf. I have considered that maybe only one character or byte is inside of inMessage.Buf; however, according to the check I did above on the actual received size, everything seems accurate.

    Am I not converting inMessage.Buf correctly?


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Winsock issues
    By tjpanda in forum Windows Programming
    Replies: 3
    Last Post: 12-04-2008, 08:32 AM
  2. Winsock Messaging Program
    By Morgul in forum Windows Programming
    Replies: 13
    Last Post: 04-25-2005, 04:00 PM
  3. Where do I initialize Winsock and catch messages for it?
    By Lithorien in forum Windows Programming
    Replies: 10
    Last Post: 12-30-2004, 12:11 PM
  4. AcceptEx with WSASend and WSARecv :: Winsock
    By kuphryn in forum Networking/Device Communication
    Replies: 2
    Last Post: 10-05-2003, 08:48 PM
  5. WSASend & WSARecv :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-16-2002, 05:51 PM