Closed Boguinhos closed 4 years ago
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.
Hello there! I’m self learning on how to program and i’m trying to go async on a little project i have but i’m struggling with this library as the example provided is not something i can fully understand. But i found this old example on the issues (from 2016) that i got working. But i think i’m not going the right way. I need to make a get request for like 4 to 10 sequencial local ips as fast as i can. The request is as basic as it gets as i don’t need the reply, just to send the get request and if i could i would discard the server’s reply if that could make it faster. I think i made it work by cheating as this routine checks if aClient exists and if it does it returns. As i need to send several fast requests and i only was able to complete one, i removed the object existance validation so that i could use the same object for all the iterations i need. And it worked. But it’s speed is not constant, sometimes it seems fast but next time it can be not so fast. I do not get consistant results. I was thinking on creating a new async client object for each request but as the number of requests i need should be dynamic i think i cannot make new objects in a for loop. How could i make several fast requests?
This is the example i got: ' static AsyncClient * aClient = NULL;
void runAsyncClient(){ if(aClient)//client already exists return;
aClient = new AsyncClient(); if(!aClient)//could not allocate client return;
aClient->onError([](void arg, AsyncClient client, int error){ Serial.println("Connect Error"); aClient = NULL; delete client; }, NULL);
aClient->onConnect([](void arg, AsyncClient client){ Serial.println("Connected"); aClient->onError(NULL, NULL);
}, NULL);
if(!aClient->connect("www.google.com", 80)){ Serial.println("Connect Fail"); AsyncClient * client = aClient; aClient = NULL; delete client; } }'
Thank you!