Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Reducing overhead: do I have to keep closing and recreating the httpconnection?

Author
Message
Jambo B
14
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 6th May 2017 16:28 Edited at: 6th May 2017 16:30
Hi all:

Would you mind having a look at this code? It's not good, but will illustrate my point:



Sections 1 and 2 behave as predicted, popping up the message.

Here's where things go a bit awry, though. In section 3 (the loop), the message from File2 keeps being displayed. That is, GetHTTPResponseReady continues to return 1.

I would have thought (wrongly) that once I had used GetHTTPResponse in section 2 to save the response, GetHTTPResponseReady would return 0, in readiness for the next one.

Is there any way to 'reset' HTTPResponseReady to 0 without closing and recreating the connection? Seems like unnecessary overhead.

Thanks,

James
Jambo B
14
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 7th May 2017 13:47
Is each HTTPConnection designed to be used once, and than deleted when the response is received?
JohnnyMeek
10
Years of Service
User Offline
Joined: 23rd Apr 2013
Location: Slovenia
Posted: 7th May 2017 16:18
I've had mixed experiences with Android and iOS. I would open a connection and leave it, which seemed to work fine on iOS but would fail on Android occasionally.

Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th May 2017 18:21
The default nature of an HTTP connections is not persistent. It grabs what it needs then dies. If you want to keep a persistent connection, AppGameKit needs a keep-alive option.

To me it sounds like it's not emptying the buffer after you've read the response, likely assuming you planned on closing the connection. If there's no option to manually empty it and it won't do it on its own, then I'd see no other option than to reopen a new connection.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Preben
AGK Studio Developer
19
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 9th May 2017 09:27
The problem is the web server , apache web server have a default keep alive of 5 seconds , so the web servers will close your connection after 5 sec. sure you can adjust this on the server but all web servers will have a low keep alive ( to free up connections ). You can avoid this if you keep sending data to the webserver.

Try this sample;


The php code agk2.php just response with the same data you sent but * 10 times to emulate a data flow.

best regards Preben Eriksen,
Jambo B
14
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 10th May 2017 20:55
Thanks to all for your responses. I've messed around with it, and decided to open a new connection each time. That seems to work ok.

James
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th May 2017 00:41
It shouldn't affect performance when you consider how many webpages you visit probably make 50 different connections. I installed a firewall on my phone to monitor outgoing connections. I couldn't believe how many different ad servers some games would connect to, I'm talking about dozens at a time!

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-04-16 11:12:28
Your offset time is: 2024-04-16 11:12:28