Skip to content

[C++ Networking] Http Nginx Keepalives #1651

@halx99

Description

@halx99

Discussed in #612

Originally posted by DelinWorks March 31, 2022
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:

image

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

image

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->setRequestType(network::HttpRequest::Type::GET);
request->setUrl("https://delingames.xyz/accounts/load_score.php?uid=1");
request->setResponseCallback([&](network::HttpClient* client, network::HttpResponse* response) {
    if (response->isSucceed()) {
        // process request from server
    });
network::HttpClient::getInstance()->send(request);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions