A brief description of the requirements: the game to join the event log, such as the player up to level 10, create a role, or, after triggering these events, ask the client to forget the background to throw a log message. In general, we can directly use Cocos's own httpclient (the bottom with Libcurl implementation) to deal with, but many times, our game other logic is also used httpclient, such as login, download resources and so on, which may lead to a problem, If a time client generates multiple error logs (or the log server has limited bandwidth and lots of concurrency), the sending of these log requests will inevitably affect the main game logic and preempt the Curl queue.
Also mention a feature of curl, when we call the Curl_easy_perform function to execute the request, we must wait until the server returns the result before continuing, that is, if the background server responds to delays for other reasons, the entire Curl queue waits.
How to solve the above embarrassment? Obviously, the game logic must be prioritized in comparison to log requests. So we let the log request go another way, scenario: the HTTP implementation of the iOS SDK. Very simple, and, thrown away without a tube to return! Ideal for logging this type of demand
The following is a simple code, for Android is similar, we can use the Android SDK inside the HTTP method to achieve
voidSendHTTP (Const Char*url0,intmethod) {NSString*url =[NSString stringwithutf8string:url0]; Nsmutableurlrequest*request = [[Nsmutableurlrequest alloc] init];//Autorelease];[Request Seturl:[nsurl Urlwithstring:url]; if(Method = =0) {[Request Sethttpmethod:@"POST"]; } Else{[Request Sethttpmethod:@"GET"]; } nsurlconnection*connection = [[Nsurlconnection alloc]initwithrequest:requestDelegate: nil];}
Cocos2d-x another implementation of HTTP requests under iOS