|
-
April 1st, 2007, 05:07 PM
#1
Winsock recv() problem !
Code:
char buff[5];
CString htmlSource;
int rb=recv(conn,buff,sizeof(buff),MSG_PEEK);
while(rb>0)
{
rb=recv(conn,buff,sizeof(buff),MSG_PEEK);
htmlSource+=(CString)buff;
}
return htmlSource;
A very usuall recv() !
I use it to get a http request's response from a server
the problem is that i always recieve the response followed by request i sent !!!
which looks like that...
Code:
Host: www.site.com
Connection: Close
...ect
ny one got a clue whats wrong ?!
-
April 1st, 2007, 06:21 PM
#2
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
-
April 6th, 2007, 02:23 AM
#3
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|