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 / Cache Issue

Author
Message
kozma_11
21
Years of Service
User Offline
Joined: 17th Sep 2003
Location: Scotland
Posted: 27th Feb 2017 22:01
Hi,

I'm hosting some txt files that my app downloads for use in a high score board. I've reset the score board online but when I compile and run the app in AppGameKit, and try and download the high score file, it appears to be defaulting to a cache version or something as it doesn't download the latest version (although the code all runs like it has downloaded successfully). This is really annoying when it comes to testing the app! Any ideas to fix would be appreciated, I'm running AGK2 on Mac.

Thanks!

John
El Presidente
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 28th Feb 2017 09:38
Quote: " I've reset the score board online"

But do you delete the copy downloaded to the device?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Feb 2017 10:41
I do something similar, and don't have a caching problem. Are you reading the right file from the right folder?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
kozma_11
21
Years of Service
User Offline
Joined: 17th Sep 2003
Location: Scotland
Posted: 28th Feb 2017 20:51
Thanks for the replies. Mobiius, yes I check if the old file exists and delete it prior to downloading the new file.

BatVink - I don't change any of the folder settings so assume all my downloads go to the "write" folder, where I then read them in from there using 'Open to Read'.

Here is my main function to download the file from the server:


Function DownloadSEASONFile()

value = 0 rem set this as failure until file is downloaded

host$ = "excel.starting11stats.co.uk"
file$ = "ppfmseason.txt"

rem delete any existing file first
If GetFileExists("ppfmseason.txt") = 1
DeleteFile("ppfmseason.txt")
EndIF


Rem Display MessageBox
DrawImage(1,970,5,100,100,1080,520)
SetSpriteDepth(970,2)


rem text
BoxText(1,"Downloading Season Best High Scores.....",640,260,950,2,44,-13,1)
SetTextDepth(950,1)
Sync()

Pause(0.5)


http = CreateHTTPConnection()
SetHTTPHost(http, host$ , 0, "","")

//Print ("Connecting...........")
Sync()

//Initiate the request - I prefer async so we can give the user a waiting screen while the connection is working.
SendHTTPRequestASync(http , file$ , "")


time0 = GetMilliseconds()
timeElasped = 0
done=0
repeat
timeNow = GetMilliseconds()
timeElapsed = (timeNow - time0)

rem Print("Connecting to ICC FC server.......") //Here we'd have an actual waiting animation or message.

ready = GetHTTPResponseReady(http)
if ready <> 0 or timeElapsed > 60000 //set a timeout limit
done = 1
endif

Sync()
until done = 1

if ready = 1
// We got a response! We're not using response codes this time for simplicity.
GetHTTPFile( http, file$, "ppfmseason.txt" )

while GetHTTPFileComplete(http) = 0

//Print ("Downloading: " + str(Round(GetHTTPFileProgress(http)))+"%")
Sync()
endwhile

//Print ("Downloading: " + str(Round(GetHTTPFileProgress(http)))+"%")
Sync()

value = 1


elseif ready = -1
//Report there was a connection error - this could happen due to a lost internet connection or the server failed to respond.
//msgbox = MessageBox(1,"There was a problem with the connection","OK","", "Please try again later","",4,0)
DeleteText(950)
DeleteSprite(970)

MessageBox(0,"There was a problem with the connection","Please try again later","","","OK","")

endif


CloseHTTPConnection(http)
DeleteHTTPConnection(http)

DeleteText(950)
DeleteSprite(970)

EndFunction value


I've set a message before and after to make sure the file doesn't exist prior to calling the function and that it does afterwards with no issues. I think it's something to do with this function. If I run this code now and then just opentoread the txt file, the first line I'm getting using Read line is "1000000,Unknown,Unknown,420,1,0,0,0,0" but I know the text file online the first line is "1000000,94fd,John,420,1,0,0,0,1" as I changed it about half an hour ago. I thought it was a cache issue as yesterday it wasn't even showing the first line as the Unknowns but today it is. Then when I update the text file manually online and then re-run, it appears to download the new file but it still shows the old data? So now I'm a bit stumped! Would appreciate any feedback, especially if you can spot something wrong with this function!
El Presidente
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 28th Feb 2017 22:39
is this ppfmseason.txt part of the media folder?
AGK (Steam) V2017.01.09 : Windows 10 Pro 64 Bit : AMD (16.12.1) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 1st Mar 2017 08:46
And don't forget your [ code ] tags when posting code
Preben
AGK Studio Developer
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 1st Mar 2017 18:46
Just add a random number after your file to prevent cache , your computer could cache , a 3rd service like cloudflare could cache , you could have some cache software running on the webserver so...

file$ = "ppfmseason.txt?randomnumber"

best regards Preben Eriksen,
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 1st Mar 2017 19:25
normal the webserver will look at the saved file date.
a proxy can do his job wrong or the http request header is wrong.
you can look if a firefox browser will show always the correct file.
AGK (Steam) V2017.01.09 : Windows 10 Pro 64 Bit : AMD (16.12.1) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
kozma_11
21
Years of Service
User Offline
Joined: 17th Sep 2003
Location: Scotland
Posted: 1st Mar 2017 20:13
Markus - the ppfmseason.txt isn't in the media folder when I compile and run the game. It only exists when it get's downloaded and then it's deleted after use. I'm assuming when I download it, it goes to the 'write' folder and when I delete it, it will delete the same file in the write folder? When I run GetFileExists, I think this checks both Media and Write folders and it returns 0 before I download the file so it does not exist on the device before I download it.

Just ran the same code as yesterday today after booting up the mac, and it downloads and displays the latest version. Then again, I go online and change the file, run the code and it still shows the old data! I'll try Preben's idea and see if that helps.

Thanks for the replies!

John
El Presidente
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 1st Mar 2017 20:42 Edited at: 1st Mar 2017 21:52
maybe also look into http header, maybe you can send some cache control informations with the file, or they are missing.
https://www.keycdn.com/blog/http-cache-headers/

if you request a file/data via http the answer its a combination of header information and the data.
PHP
https://stackoverflow.com/questions/4480304/how-to-set-http-headers-for-cache-control
AGK (Steam) V2017.01.09 : Windows 10 Pro 64 Bit : AMD (16.12.1) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
kozma_11
21
Years of Service
User Offline
Joined: 17th Sep 2003
Location: Scotland
Posted: 1st Mar 2017 21:35
Preben - I can't change the file name as this is the name of the file online? I have tried renaming the downloaded file on the device but it still reads the previous "cache" version of the online file.

I'm hoping it's just something to do with my Mac and where it stores a cache of the downloaded files. I'm going to create an APK and put on my phone and see if it works the same way as on my Mac or if it works the way it should
El Presidente
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 1st Mar 2017 21:41 Edited at: 1st Mar 2017 21:43
? is a delimiter, then comes the parameters
https://forum.thegamecreators.com/thread/218969?page=1#msg2597951&blah=6

?randomnumber
is a dummy in url
AGK (Steam) V2017.01.09 : Windows 10 Pro 64 Bit : AMD (16.12.1) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
kozma_11
21
Years of Service
User Offline
Joined: 17th Sep 2003
Location: Scotland
Posted: 1st Mar 2017 21:54
Thanks Markus! The header stuff looks a bit beyond me!

But got the random number thing, thanks. I've tried adding it in to the file$, but it still doesn't appear to be downloading the latest version on my mac, however if I broadcast the app to my iPhone, it does work properly in that I downloaded the online file, then changed it online and re-ran it. It downloaded the new file now, where as if I run it on the mac it still seems to be using some cache version of the downloaded file.
El Presidente
kozma_11
21
Years of Service
User Offline
Joined: 17th Sep 2003
Location: Scotland
Posted: 1st Mar 2017 22:01
Sorted! Thanks Preben & Markus!

Appears Preben's solution is now working on my mac! Didn't seem to at first but I've now tried changing the online file a few times and it now changes on the app when I try to download the latest version!

Woohoo! Not long now until I get my game finished now that the high score working! (Premier Picks Football Manager if you're into football games )
El Presidente

Login to post a reply

Server time is: 2024-09-29 23:33:42
Your offset time is: 2024-09-29 23:33:42