Cocos2d-x another implementation of HTTP requests under iOS

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.