I am sending an Httprequest using CCHttpClient::getInstance()->send(pRequest);
And I want to wait for certain time, if response didn’t come(ie. internet is slow), I’d like to cancel that request.
Is it possible to cancel the request which is already sent ?
Another option for me is to set the timeout of cchttpclient,but my application is crashing when I try that.Did anyone try that ? Please share the code
Let me explain what am doing:
I have a Reachability class ,which will check for internet connection status.
I am calling its function from Appdelegate.cpp .
the function looks like :
I have an onRequestCompleted() handler and a scheduled funtion checkForResponse().
if onRequestCompleted() is fired first, I am taking the connection as proper.
if in onRequestCompleted() , if response is null,it is no connection.
And if onRequestCompleted() is not fired within time interval MAX_RESPONSE_TIME , the sceduled function will be fired first and this case I am taking as slow connection
When it is proper connection, I am starting other downloads.
But my app crashes occasionally even if it returns proper connection.
We’ve totally rewritten CCHttpClient for our game, to include support for canceling pending requests (no support to cancel an ongoing request), configurable timeouts and retries. Unfortunately it’s no longer compatible with the original class (as we switched from strings to integers for tags (easier to handle in a switch statement :)).
We had to rebuild libcurl with support for SSL and added libssl, libcrypto and libcares as well. I would suggest to include them in standard cocos2d-x, as most probably all developers will need secure connections for communicating with their servers.
You need to actually set NULL to all the callbacks in the Scene before you actually exit the scene. So that there is no bad memory pointers. In your case,
_pRequest->setResponseCallback(NULL);
Need not to say, if you want to handle the callbacks of current scene in the new scene then you need to set the reference of new scene in the present scene’s callbacks.
PS: There error situtation you are facing is called as dangling pointer in C++.
Hi
Can anybody help me with almost the same problem. In my case I have a lot of images to download from different sources. But when user switches screen I need to cancel all downloads (because new images will be only in a queue and I need them to be downloaded immediately). How can I do this?
have you made the pull request? I really need that cancel transfer feature in my game. I don’t really need ssl, so maybe I’ll try to re-adjust the code