So currently I am starting to work on a 2d top down space shooter game, and I have just got to networking. So far the client can draw a ship at a desired x, y and rotational coordinate with any set of vertex data (referenced from pre-existing vectors of data). The problem I am having is just the main idea of how the game loop should revolve around the networking. My idea was have each loop of the game set to 1000/60ms, and then ask the server for some data, render it and sleep for the remaining time in the frame. Problem with that is that I realised a normal ping to a game server is around 100ms, meaning the game would only be getting around 10fps. The solution I assume is to only receive events 10 times a second versus the 60 refreshes the game is getting, but how would you render and be polling to receive data at the same time? Finally I am using enet as the networking library if anyone is interested because it seems to be pretty simple in its concept, but if there is a better one for this type of game out there it would be nice to know. (I did try googling all of this stuff but its kind of hard to describe exactly what I am confused about, so thanks for any help).


If you are using ENet you could make the server send an update packet for example 5 times a second, and use a non-blocking function to process it in your client.

A non-blocking function just checks if any packet has received, does not wait for one to arrive in case one hasn't already.

In ENet you can use

int enet_host_service( ENetHost* host, ENetEvent* event, enet_uint32 timeout )

Where the last parameter is how much to wait for an incoming event( can be a pakcet, but can be connection or disconnection request too )

You can use the documentation as a reference.


As per request in comment here is how should your main programloop look like:

while( running )
    ProcessInput(); // Check for user input and process it
    UpdateNetworking(); // Send receive neccessary packets with enet_host_service
    Update(); // Update game logic
    Render(); // Render current scene
  • \$\begingroup\$ Well yea I knew about that function but my question was more of how can I poll for network activity like that while rendering at the same time. \$\endgroup\$ – Lemon Drop Dec 23 '13 at 2:31
  • \$\begingroup\$ @lemondrop Edited answer to show off programloop too. \$\endgroup\$ – akaltar Dec 23 '13 at 11:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.