Archived

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

Ratman

Non-blocking Accept

Recommended Posts

Ratman    181
Im reading Multiplayer Game Programming to kind of wade into network programming. I also have Windows Socket Network Programming. I need to use sockets (not DirectPlay). The game Im making is turn based, so its not very network intensive at all. Im using this game sort of as a steping stone to get a better idea for network programming. So I decided to use the SocketObject that the author provides in MPGP. SOOO.. what Im looking at is the Accept function. Its a blocking call, so the program hangs while waiting for a client to join. Im looking for a way around this, or at least a way the user can press Esc to cancel or something. I''ll probably have to use threads. I looked at the SocketObject''s vGetPacket method for an example, but cant really come up with a way to make a similiar method with Accept. If someone can help me out I''d be very greatfull. Everything else in the game works fine using the SocketObject, its I cant have the Accept function being a blcoking call. Thanks Ratman --------------- Ratfest.org

Share this post


Link to post
Share on other sites
Martee    476
Well, I don''t know about the internals of the SocketObject class ... but you can turn a normal socket into a non-blocking socket like so:
fcntl(socketDescriptor, F_SETFL, O_NONBLOCK);

You could also use asynchronous sockets with select(), but I''m not too familiar with that


~~~~~~~~~~
Martee

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
If your going to use non-blocking sockets under winsock you have 2 choices. You can use the BSD non-blocking sockets, where you use select to poll the state of the socket, and handle the events when they occure, or you can use the windows specific asynchronus sockets, where you hook sockets up to the windows event loop, and handle the socket events within the winproc.

Look on this website for more info.

http://www.cyberport.com/~tangent/programming/winsock/

Good Luck

-ddn

Share this post


Link to post
Share on other sites