Winsock recv function

  • Thread starter Thread starter Jay
  • Start date Start date
J

Jay

Hey There,
I have a situation that is occurring that I need help in
understanding. I have a thread that has a recv function in it, and I
have a child thread of that original thread that processes the data.
The parent thread will execute a bunch of recvs normally, but then will
read less data than is there. For example, if I expect a packet of 1056
bytes, only 284 are returned from the recv. When I put a Sleep()
function before the recv call, then it will receive the full 1056 bytes
and continue on it's merry way. What in recv could cause this?

-Jay
(patelj27b at gmail dot com)
 
Jay said:
I have a situation that is occurring that I need help in
understanding. I have a thread that has a recv function in it, and I
have a child thread of that original thread that processes the data.
The parent thread will execute a bunch of recvs normally, but then will
read less data than is there. For example, if I expect a packet of 1056
bytes, only 284 are returned from the recv. When I put a Sleep()
function before the recv call, then it will receive the full 1056 bytes
and continue on it's merry way. What in recv could cause this?

The connection is stream oriented rather than message oriented. When recv()
completes successfully, the only thing that you can be sure of is that there
is at least one byte data. It is left for the application to call recv() as
many times as is necessary.

For that reason, applications need to define their own way of delimiting
messages. Sometimes that is done by prepending a header in which the length
of application data is specified at a fixed spot in the header. Other
applications use a sentinel byte to indicate logical end of message. And
some senders simply close the connection so that the failure of a subsequent
recv() is taken to mean that all data has been received.

Regards,
Will
 
Back
Top