Re: Winsock recv() problem !
Why are you just peeking at the data?
Code:
rb=recv(conn,buff,sizeof(buff),MSG_PEEK);
You append the data whitout checking if any (or how much) data was received. If you want to treat data received using recv as a c-string (zero ended), you need to add the zero yourself. Something like:
Code:
while(rb>0)
{
rb=recv(conn, buff, sizeof(buff) - 1, 0); // make room for ending zero
buff[rb] = '\0'; // add ending zero
htmlSource += (CString)buff;
}
And maybe you're better off with a do-while statement:
Code:
char buff[1024];
CString htmlSource;
do
{
rb=recv(conn, buff, sizeof(buff) - 1, 0);
buff[rb] = '\0'; // add ending zero
htmlSource += (CString)buff;
} while (rb > 0);
return htmlSource;
- petter
Re: Winsock recv() problem !
i peeked data coz i always got the recv function to return the same # of bytes recieved with no new data !...and so i got into an endless loop
ny ur code snippet helped alot...thnx mate