Cocos2d-x behaviour with networking (HTTP) in suspend

Cocos2d-x behaviour with networking (HTTP) in suspend
0.0 0



I’m trying to understand how networking (sending a HTTP request) will behave when the app enters suspend.

The use case is: As not to bombard the server with requests we are buffering commands and sending them every (for example) 10 seconds. We pack many commands together in one HTTP request to our server and send. We’d like to handle graciously the case when there are commands in the buffer and the user presses suspend. We’d like to send off the buffer to our server - otherwise if the user does not contact the server in a limited amount of time he will lose the progress that was not sent. Lets ignore the case when the user kills the app - lets just say he received a very long phone call or switched to another app.


  • What will happen if suspend is called right in the middle of a HTTP request (slow network)? Will it finish?
  • Is it safe to send off the packed in AppDelegate::applicationDidEnterBackground using curl? What happens if this takes time (slow network again) and we delay the return from applicationDidEnterBackground?
  • We’d like to use libcurl for portabiliy, but if that is not possible we found that on Android we can process lenghty calls on the native side using a Service and on iOS we can use beginBackgroundTaskWithExpirationHandler… this however includes coding native (and probably moving the whole HTTP client functionality to native). Does cocos2d-x have such functionality or must it be implemented?

Any insights, suggestions on how to best handle this case would be very appreciated.

Best regards,