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 / Code: Determining whether AGK successfully downloaded a file

Author
Message
anwserman
12
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 26th Jun 2012 04:53 Edited at: 26th Jun 2012 04:54
This is the only code in the module (main.agc). You should just have to copy and paste it.

I discovered that AppGameKit returns a zero-size file when you attempt to download a file from the web with no internet connection. This can be used to determine whether or not a user is connected to the internet.

Secondly, if the app starts downloading, it will keep downloading until the file is downloaded - even if the internet connection is dropped during the download. By using this, if AppGameKit says the file is done downloading, you're good to go. Otherwise, count how long it takes. This code times out after 25 seconds, and says that the connection was lost (and deletes the partially downloaded file).

To test this out
1) run the app with full internet connection, wait to finish
2) run app again without any internet connection, wait to finish
3) run app again and kill the internet connection a few seconds after the app starts

You'll get all three outcomes. The only sizable file I had on my webserver was my Water app, and it's 20MB. This is a decent sized file that allows you to accurately test all three scenarios above (it takes about 20 seconds to download onto my PC at least).

The code isn't the best, but it's the best working sample I found so far on here that provides basic error-checking on any downloaded file!
-Jeff



Hi there. My name is Dug. I have just met you, and I love you.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Jun 2012 09:11
Nice, thanks for sharing.

JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 26th Jun 2012 13:54
It would be infinitely more sensible if these functions could return a result.

In the first place Connect() ought to return (say) 0 for OK and -1 for Couldn't Connect. The same goes for GetFileAsync(). All the socket layers will either report an error or throw an exception, so I can't see why this can't be returned as a state result.

-- Jim
anwserman
12
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 26th Jun 2012 14:25
Quote: "It would be infinitely more sensible if these functions could return a result.

In the first place Connect() ought to return (say) 0 for OK and -1 for Couldn't Connect. The same goes for GetFileAsync(). All the socket layers will either report an error or throw an exception, so I can't see why this can't be returned as a state result."


I 110% agree, however you work with what you have. Like all programming languages, there are some things that are infinitely easier to do in others while some things are harder. I'll take this tradeoff for rapid development =)

Hi there. My name is Dug. I have just met you, and I love you.
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 26th Jun 2012 18:36
I don't want unnecessary tradeoffs. I think these calls should return results. It's not sensible to descend through a lot of error states without any feedback. You can give it a rubbish URL and a non-existent file, (tried it) and it will cheerfully tell it's done the job.

This should be fixed.

-- Jim
anwserman
12
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 28th Jun 2012 04:43 Edited at: 28th Jun 2012 12:39
I updated the code. It only uses this one function and will return the status result as a return variable. Paste this into a new file and you're good to go.



made a couple small changes to fix bugs

Hi there. My name is Dug. I have just met you, and I love you.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Jun 2012 14:34
cool


this.mess = abs(sin(times#))
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 28th Jun 2012 15:19
I think I'll raise it as an enhancement request. It's not secure or elegant to have do it that way.

-- Jim
anwserman
12
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 28th Jun 2012 16:15
Quote: "I think I'll raise it as an enhancement request. It's not secure or elegant to have do it that way."


Then I'll have to recode it once they change it. Thanks for the help there, Jim

Hi there. My name is Dug. I have just met you, and I love you.
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 28th Jun 2012 17:31
I have raised it as an issue.

Ideally we check the file size before initiating the download. If it's zero it probably doesn't exist. Otherwise, when download is complete or times out, we can check expected against actual file length.

-- Jim
anwserman
12
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 28th Jun 2012 17:35
That works for me. Great thinking =)

Hi there. My name is Dug. I have just met you, and I love you.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 28th Jun 2012 18:10
I tagged the issue as 'confirmed' in both the Google Issue list and the TGC AppGameKit Community Tester page (version 1.0):
http://www.tgcct.triassicassociates.com

Cheers,
Ancient Lady
AGK Community Tester

Login to post a reply

Server time is: 2024-05-02 11:52:34
Your offset time is: 2024-05-02 11:52:34