Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

recv() issues

Status
Not open for further replies.

ForeverCode

Programmer
Dec 6, 2002
41
US
I'm having a problem recieving data...
Whenever my code goes into a loop to get the data it stops on recv() and waits for more data once all the data has been read. I dont want this to happen. Is there any way to fix the following code so that once all the data has been written the loop exits and i can handle the data?

CString Data;
while(bRead = recv(Sck, Buff, 8192, 0) != 0){

if(bRead < 0) break;

Data += CString(Buff, bRead); //append
Sleep(100);
}
 
If I understand what you are asking, you want a non-blocking socket. Use the following when you create the socket:

unsigned long FIONBIOparm=1;
int ret;

ret=ioctlsocket(sck,FIONBIO,&FIONBIOparm);

You then need to put the recv() into a loop. If there is no data yet it will return with SOCKET_ERROR. Test WSAGetLastError for WSAEWOULDBLOCK. This is the normal return when there is no data to read.
 
My pleasure. I have gotten so much out of this forum, it is nice to give a little something back. Socket programming is the one thing I am comfortable with.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top