Jump to content
  • Advertisement
Sign in to follow this  

Problem with sockets and SDL

This topic is 4853 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

The call to recv blocks until data is available. If you call recv on the same thread that does the rendering, your screen will not be updated.
To solve this, you can either use non-blocking I/O (Google has quite some arctiles on that), or run your network and rendering code in separate threads.

Share this post

Link to post
Share on other sites
Thank you, this seems to be what I am looking for. I added:

fcntl(serversocket, F_SETFL, O_NONBLOCK);

to my client, which no longer hangs when it's not receiving anything from the server. However, it seems to continously receive the same data over and over again, although the server isn't sending anything(?). But I will investigate this further through Google, now that I know what I'm searching for.

Thanks again!

Share this post

Link to post
Original post by hplus0603
Also, you should test the return value from recv(), because if there's some error, your loop will spin forever.

Thanks for the tip! This is how I did it (if anyone else is having the same problem):

int i;

i = recv(serversocket, buffer, sizeof(buffer), 0);
if (i > 0) {
we can continue and process the received data

Share this post

Link to post
Sign in to follow this  

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!