NAME

gc_clients_service - services clients and manages network messages.

SYNOPSIS

#include <game-carrier/client.h>

GC_CLIENT_API
GCT_INT gc_clients_service(void);

RETURN VALUE

Returns 0 if the operation is successful.

Standard error codes like EINVAL are returned if an error occurs.

DESCRIPTION

The gc_clients_service services network clients, processing incoming messages and dispatching them to the appropriate handlers.

You can invoke this function only if the library was initialized by the gc_clients_init function in Passive or Hybrid modes, otherwise it will return an error.

Both Passive and Hybrid modes perform network operations using an internal queue. All events must be processed by calling the gc_clients_service function in the same thread where the gc_clients_init is initialized. Calling the function from multiple threads may result in undefined behavior. To avoid network lags, the game may need to call the function frequently. The function is typically called during each iteration of a game loop.

EXAMPLE

#include <game-carrier/client.h>

#include <stdio.h>

int mode = GC_MODE_HYBRID;
int finished = 0;

int main(int argc, char * argv[])
{
    /* Client library initialization */
    int ret = gc_clients_init(mode);
    if (ret != 0) {
        fprintf(stderr, "Failed to initialize the Game Carrier client library\n");
        return 1;
    }

    /* Game loop */
    while (!finished) {

        /* Perform related game activity, like drawing a new frame */
        draw_new_frame();

        /* Handling network */
        if (mode == GC_MODE_PASSIVE || mode == GC_MODE_HYBRID) {
            gc_clients_service();
        }
    }

    /* Client library finalization */
    gc_clients_cleanup();
    return 0;
}

SEE ALSO

gc_clients_init, gc_clients_cleanup