Jump to content
  • Advertisement
Sign in to follow this  
SoxFan44

C++ and sockets, help please!

This topic is 4443 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; } retcode = recv(sock, recvBuff, BUFFER_SIZE, 0); }

Share this post


Link to post
Share on other sites
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!