Winsock, weird sideeffect

This is a discussion on Winsock, weird sideeffect within the Networking/Device Communication forums, part of the General Programming Boards category; I got this odd error where if I send some data from a client to a server the message is ...

Winsock, weird sideeffect

I got this odd error where if I send some data from a client to a server the message is received but I also get a number of empty messages, the same amount as the nr of letters in the message (in the example below, the string "Hello" gets 5 empty messages.
It's a non-blocking system, the client sends simply using send() and the server's recieve-part looks like this:

MSG_PEEK fills the buffer just the same the only difference is that the data isn't removed from wnsock's internal bufers so another recv call would return the same data. I don't recomend using MSG_PEEK EVER!
To get the amount of data available use ioctlsocket with the FIONREAD flag.
The 3rd argument to recv isn't the amount of data you want to receive it is the length of the buffer where the data will be placed so if there is less data then the buffer length recv will still return with no error, the amount received is the return value.

"MSG_PEEK: Peeks at the incoming data. The data is copied into the buffer, but is not removed from the input queue. The function subsequently returns the amount of data that can be read in a single call to the recv."

but on closer inspection:

"...which may not be the same as the total amount of data queued on the socket".