Sign in to follow this  

C++ and sockets, help please!

This topic is 4105 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I don't understand what I'm doing wrong here, my program gets the data from the buffer and prints it to the screen, but it apprears not to exit the for loop for some reason. If anyone can tell me why I'd appreciate it. Thanks! int recvBytes = 0; int retcode = recv(sock, recvBuff, BUFFER_SIZE, 0); while((retcode > 0) || (retcode == -1)){ if(retcode == -1){ cout << "error" << endl; } for(int i = 0; i < retcode; i++){ cout << recvBuff[i]; } retcode = recv(sock, recvBuff, BUFFER_SIZE, 0); }

Share this post


Link to post
Share on other sites
Quote:
Original post by Dave Weinstein
If you haven't made this a non-blocking socket, it will block execution once there is no data coming in, if the sender hasn't closed the connection.


It's doing a HTTP GET, so once all the data is sent by the server wouldn't the web server close the connection? This is how I'm creating my socket, is this right?

s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

Share this post


Link to post
Share on other sites
Quote:
It's doing a HTTP GET, so once all the data is sent by the server wouldn't the web server close the connection?


If you're using HTTP/1.1 (which most servers are these days) then the connection will likely stay open (to be re-used) unless you emit a specific Connection: close header in your request.

If you want to look at a simple HTTP request code sample, check out the source for HTTP-GET, which is a very small HTTP get implementation.

Share this post


Link to post
Share on other sites

This topic is 4105 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this