Does HttpRequest support keepalives for connections?

I’ve set up an nginx server so I can host my login and signup system for this game and load the scores

Problem is that I’ve told nginx to keep the connections open for 120 seconds and it seems that whenever I send a request through my game the connection gets released and not kept alive. I’ve known this because chrome keeps the connection for exactly 120 secs using NetLimiter and when I inspect the game using NetLimiter the game just releases the connection as soon as the request is done

Why would I keep connections alive? it’s because when you’re working with multiplayer games you want to minimize the amount of tcp connections to be initialized. so that the server and the game feel fast

As you can see chrome keeps the connection alive as said in nginx config:

But the game keeps dropping the connection as soon as the request is finished:

So how would you go about implementing this in c++ ? (Keeping connections alive for later use)

I initiate connections this way

auto request = new (std::nothrow) network::HttpRequest();
request->setResponseCallback([&](network::HttpClient* client, network::HttpResponse* response) {
    if (response->isSucceed()) {
        // process request from server

I dont know why you want to use keepalives for this feature because normally in multiplayer games either websocket/ is being used or auth-token is used while calling HttPRequest for authentication (You can set in Headers or RequestData).
Anyways still you want to go with keepalives then try directly using CURL, as behind HttpRequest cocos is using CURL only.
May be this can help

1 Like

websockets are kinda complex for my simple example.

https is better for not so intensive multiplayer games like card game.

games like osu use https keepalive they’re neatier than websockets.

Thanks for you suggestion! totally forgot.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.