network question

Started by
3 comments, last by hello_there 21 years, 3 months ago
when you call listen() does it keep listening even if you don't call it again? for example i should only call it at the start of my game and not call it every frame? also should i call accept() every frame. and what does accept() return if there's no user wait to be accepted. [edited by - hello_there on January 18, 2003 10:29:41 PM]
____________________________________________________________How could hell be worse?
Advertisement
You call listen() only once, usually right after you''ve created your listen socket. Call it at the start of your game, not every frame.

The accept() function will block (not return) until it accepts a new connection (or encounters an error) unless it is called on a non-blocking socket. This can be a serious problem, since you probably want to be doing other things in your game, not waiting around for somebody to connect.

How often you call accept() is up to you, but once per frame would probably be sufficient.
say i want to keep checking if someone is trying to connect and accept them if there is and still play the game what would i do? call it once per frame or put it on non-block or what ever.
____________________________________________________________How could hell be worse?
among the alternatives:
put it in a separate thread, or
use wsaasyncselect, or
use a nonblocking socket and poll it with select or wsaeventselect every now and then, or
use acceptex
Unless you have experience with multi-threaded code, I would suggest you poll the listen socket with select() once per frame.

Here''s a reasonably good example: http://tangentsoft.net/wskfaq/examples/basics/select-server.html

This topic is closed to new replies.

Advertisement