Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SocketSelector within gameloop  (Read 1893 times)

0 Members and 1 Guest are viewing this topic.

Crown

  • Newbie
  • *
  • Posts: 4
    • View Profile
SocketSelector within gameloop
« on: January 25, 2014, 01:12:22 am »
I don't want to have a separate program for client and server so I have made my main game loop with a switch that determines if the process is running in server or client mode.  The rest of the game is, of course, the same.  The problem is that the SocketSeletor::Wait() on the server portion blocks the program flow. 

What I have done is set the timeout to very low, I think 20 milliseconds, which allows my server process to run fine at 30fps.  My game isn't processor intensive and so I won't have to worry about slowing the framerate that way.  Is this an appropriate way to solve this problem?  If I'm making a game in the future that can't wait around 20 milliseconds, what should I do?  Is there a lower limit on this?  Can I wait just 1 millisecond?

Thanks.

Azaral

  • Full Member
  • ***
  • Posts: 110
    • View Profile
Re: SocketSelector within gameloop
« Reply #1 on: January 25, 2014, 05:34:00 am »
Run the blocking functions in another thread. One thread runs the game logic and sends to destination, another thread just sits and waits to receive from sender.

Crown

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: SocketSelector within gameloop
« Reply #2 on: January 25, 2014, 06:19:05 am »
Thanks Azaral, I was hoping to avoid multi-threading.  I haven't really done multi-threading before but I guess I'll have to bite the bullet and figure it out.