Asynchronous http request

Asynchronous http request
0.0 0


How to make asynchronous http requests in cocos2dx. which api i need to use .

Building cURL for Cocos2d-x Eclipse, something is missing for me

there is more solutions (for example):
1.easy interface in own thread
2.multi interface
3.multi inteface in own thread

The simples is use multi interface from libcurl (


Mr Milda


I am using pthread for http request.
I want to remove the current layer when the download is finished.
But i got a bad access when trying to getParent or removeFromParentAndCleanup.
How should I add the callback/delegate?


Hi, Leo, you had better not to invoke methods of classes which inherits from CCObject in other threads. Because #354 have not been implemented yet.
The recommended approach is to deal with the network in a new thread, and use flags, events, locks to sync with UI thread.


Hello and sorry to use an old post, but look like exactly the same question.

I link libcurl to my project, and success to download (synchronously) a JSON file. Not the best but small file so from now it’s ok.
But now I want to download small image, and I really need to do all of that asynchronous.

Did someone success of doing that ?

Like ASIHttpRequest on iPhone. I just have a callback when downloading is finish and during that the HUD isn’t freeze.

Thanks for reading,


we use multi interface, as I mentioned in my post in this forum.
I only wrap example on the link.

It works as you need (async communication upload/download with callback).

I hope that helps you.




As I don’t see callback on the example, I was trying to add one but if you just wrap this sample, I will try to do the same.

No need to make the 2 while in a looping action ?
I don’t see how can continue to play if for example my download take 30 minutes.

I will continue my try with this sample.



Ok, I find my error.
I was adding the line :
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
But I forget to add the line :
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);

So for sure the Write function was crash when using the chunk param as it wasn’t send to the function.

Now I have to use the char* of the chunk to make a CCTexture (or CCSprite).
Don’t success from now but I continue to try.

Thank you Milda, it’s working fine.