axmol
axmol copied to clipboard
Does HttpRequest support keepalives for connections?
This problem is an issue/discussion so I didn't know where to put it.
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->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);
Originally posted by @DelinWorks in https://github.com/adxeproject/adxe/discussions/612
@halx99 I think there is an option for it in yasio
I modified HttpClient.cpp
and added a line after 128 in the constructor that goes
_service->set_option(yasio::YOPT_S_TCP_KEEPALIVE, 7200, 75, 10);
I tried different values and connection objects and even made a static HttpClient client and send requests from there but it doesn't seem to do the trick, the connections go blank after the request is done.
The option is tcp lowlevel protocol keepalive, not http, currently http client not implememt http keepalive behavior
http is just a hyper text transfer protocol layer that goes on top of a TCP connection or am I wrong? The thing you want to keep open is TCP connections so that http data can pass through the same connection
The keepalive
concept is different between TCP
and HTTP
, we needs implement it for HTTP manually.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.