Non-blocking Accept

Started by
2 comments, last by Ratman 22 years, 8 months ago
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
Advertisement
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
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Hmm thanks Martee, I''ll look into that. Anyone else? LostLogic?
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

This topic is closed to new replies.

Advertisement