Sign in to follow this  

Problem with sockets and SDL

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

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