I have a big loop in actionscript that sends lots of data to an url:
for(var i=0;i<1000;i++) {
var request:URLRequest = new URLRequest();
request.url = url;
request.method = URLRequestMethod.POST;
request.data = data;
var loader:URLLoader = new URLLoader();
loader.load(request);
}
The problem is because URLLoader can make only asynchronous calls, it sends all those thousands requests at once which kills webserver.
Also it acts a bit strange on top of that. Lets say the loop is running for 5 minutes. For whole 5 minutes there is no requests coming to web server, then at the end they all are sent at once. I already tried everything I could possibly think of (empty loops, callbacks, delays) – nothing helps. All requests are sent at once no matter what.
How to make requests synchronous, so it will send one request after another? Can anyone please suggest any solution?
You can’t make synchronous call, but you can wait until the server answered back before sending another request.
But maybe there is a design flaw if really you have to send a thousand of request to a webserver in one loop ?