Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

IronFist

I need a non-blocking socket tutorial.

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

Does anyone know where I can find a non-blocking socket tutorial? I have looked around and I can only find blocking and asychronous. I have to use non-blocking because my program is a console app, so asychronous won''t work with it.

Share this post


Link to post
Share on other sites
Advertisement
select is async...and multithreading might be an unessesary step. Check out fcntl(). And also, there is no reason at all why you cant use async in a console app. While windows apps use WSAAsyncSelect(), a console app can implement the BSD select() call just like in a *nix app.

Share this post


Link to post
Share on other sites
Here''s a function you can use to toggle a SOCKET between blocking and non-blocking mode.

  
//

// Set Socket Blocking Mode

// sock = SOCKET Handle

// mode = 0 for BLOCKING, 1 for NON-BLOCKING

//

BOOL SetSocketBlockingMode(SOCKET sock, int mode)
{
unsigned long lmode = mode;

if(ioctlsocket(sock, FIONBIO, &lmode) == SOCKET_ERROR)
return(FALSE);

return(TRUE);
}


// CHRIS

Share this post


Link to post
Share on other sites

  • 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!