Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

Network request
Started by rjg7712 Nov 28 2018 04:21 PM

1 reply to this topic
asynchronous http request network request network download
This topic has been archived. This means that you cannot reply to this topic.
[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Observer

  • 2 posts
  • Corona SDK

I'm using multiple network requests and network download requests to perform http POST and Get. 


I have to send a message using POST http request and after sometime download the data at a website using GET request. I have to send the GET request to download the response until I find some required messages by parsing the xml file. And the process repeats multiple times. 


I'm not able to implement the above because the network listeners associated to each of these requests are delayed. How to ensure that the following lines of code will execute only after the network listener of the first network request is done?

[TOPIC: post.html]

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,599 posts
  • Enterprise

You have to nest your calls.


When your post completes, it will call its network listener function. at that point, you will know it's complete. You can then make your GET call inside that function.


You could optionally setup polling using a timer to call the GET request every few seconds, but this will be hard on your server and could be interpreted as a DOS attack.


Another technique would have the server generate a push notification to your app when the upload is complete to let you know you need to download the new file. This is a bit of work to setup, but if app user A uploads the file and app user B is needing to know the file was updated so it can sync the download, then this is the practical way. If it's only app user A checking to see if App user A finished uploading the file, I'm not sure why you even need to download it since you just uploaded it, but the first scenario will work.