Refreshing XML data every minute

Working on an App that requires “Live Scores” from an event.

The XML data on the remote server is updated in realtime.

Our solution is to download the XML data every minute via network.download… which doesn’t seem elegant.

The other option is to use Push Notifications, but my understanding is that it isn’t available for Android devices yet.

Does anyone have a better solution for getting the data updated every minute? We are expecting several thousand users will be accessing the data at the same time…I assume the server will be able to handle all the request…but I’m not 100% confident we will have issues.

Any suggestions? [import]uid: 64343 topic_id: 29038 reply_id: 329038[/import]

Are you sure updating once a minute is more efficient then On Demand? It certainly could be but in most situations getting the data on demand would be less overhead server side.

In any case, if you need to get data updated every minute then it seems like doing network.download(or network.request) would be the solution you would want. I would, however, look into ways of streamlining how you are sending the data and, if the data is typically large, avoid sending it when not necessary. Below are some ideas, though depending on the size of your xml they may not be worth it :slight_smile: Also, 2, 3 is something I do because I’m a cheapskate =p

  1. For starters I would switch to JSON. It will end up being less data being transferred and the JSON library makes it super simple to encode/decode between a JSON object and a Lua table.

  2. You could put in a check system where if the server-data hasn’t been updated since the last check it won’t bother re-downloading the scores.

  3. If you have a thousand of scores you probably don’t need to send them all over. Really the only relevant ones to the user are maybe the top 10/25/whatever and then their own position.

[import]uid: 147305 topic_id: 29038 reply_id: 116855[/import]

These are great tips…

This might be a stupid question… but how do I implement a check system to see if the server-data has been updated without downloading the xml file and viewing the contents?

Is there a method I am missing to check the actual XML files creation date? If so, could you kindly provide an example of a check system you have used?

Thanks in advance. [import]uid: 64343 topic_id: 29038 reply_id: 116874[/import]

Great idea…

  1. In your network listener check if lastXMLUpdate == event.response. If it does, do nothing. The scores are up to date. If it does match, move to step 5.

“If it does match”… should say “If it doesn’t match”…correct?

I am thinking my best bet at this point is to convert the XML to JSON… it seems to be a better solution for the long haul…

Thanks again!

B [import]uid: 64343 topic_id: 29038 reply_id: 116885[/import]

Well, if you wanted to check the created on date you would do it server side, in which case you would make a network request where the web service just responds with the date. It will be different depending on which web technology you use, but if I had to guess you are probably using PHP so here is a link(http://php.net/manual/en/function.filemtime.php).

I’m not really a web service guru, so there might be a more efficient way but the below method works well enough. I am going to go with PHP references but really it should be fairly androgynous. I should also mention I don’t use this implementation in anything Corona related :slight_smile:

  1. Create a page on your server that checks the modified date/time on your XML and sends it back as a response. Lets call it www.mywebsite.com/checkxml.php. The format it sends back in is irrelevent, we are really just going to compare strings anyway.
  2. In Corona, have variable called lastXMLUpdate(or whatever).
  3. When you need to check the scores you do a network request to www.mywebsite.com/checkxml.php.
  4. In your network listener check if lastXMLUpdate == event.response. If it does, do nothing. The scores are up to date. If it doesn’t match, move to step 5.
  5. Set our lastXMLUpdate = event.response since we are going to get the new scores
  6. Do your regular network.download and get the updated scores.
    [import]uid: 147305 topic_id: 29038 reply_id: 116883[/import]

You are correct, edited in case anyone else stumbles upon it in the future! [import]uid: 147305 topic_id: 29038 reply_id: 116886[/import]