Cocos2dx 3.3rc0 Diary (i)------Weak networking Curl

Source: Internet
Author: User

These two days to see the video learning the next weak networking technology, with curl, the specific use of the method I said, can refer to the official sample and the following article, explained very clearly.

"Curl (Libcurl) development" COCOS2DX's Libcurl (curl_easy) Programming tutorial (Help manual)!

Curl uses 2

I'm going to say I stepped on a hole again ... Why is it ...? 650) this.width=650; "src=" Http://img.baidu.com/hi/tsj/t_0012.gif "alt=" T_0012.gif "/> is born to trample the pit ...

first, you need to join curl.h before using the path $ (engineroot) External\curl\include\win32 and the link library libcurl_imp.lib

:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/54/52/wKiom1R-5QnwEeAhAAHezs4REyg640.jpg "title=" Qq20141203182056.png "alt=" Wkiom1r-5qnweeahaahezs4reyg640.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/54/52/wKiom1R-5QmBZKFGAAOhW6juL-w413.jpg "style=" float: none; "title=" Qq20141203182139.png "alt=" Wkiom1r-5qmbzkfgaaohw6jul-w413.jpg "/>

Below, I stepped into the pit, there are two!!!!

The first one is that I modified the sample curl_easy_setopt (Curl, Curlopt_url, "www.baidu.com"); The request failed! Failed!.... I have a sore egg ... The same as in the video why failed ...

Later changed to Curl_easy_setopt (Curl, Curlopt_url, "baidu.com"), can request success ... Don't ask why, I don't know ... I went to see COCOS2DX before the version was written like this ... There may be friends who see similar code curl_easy_setopt (Curl, Curlopt_url, "http//:baidu.com"), both of which can be written, http//: Dispensable!

The second pit is a callback function!!!!!!!

The callback functions are as follows:

size_t helloworld::write_data (void *buffer, size_t size, size_t nmemb, void *userp) {log ("%s", (char*) buffer); return size ; }

Curl_easy_setopt (Curl, curlopt_writefunction, helloworld::write_data); Set the callback function to execute curl_easy_perform (Curl) automatically called.

The same as in the video ... Or did the request fail, returning a number 23!!! Check the data to see what that means.

Curle_write_error (23) – An error occurred while writing the received data to the local file, or an error was returned to Libcurl by the write callback (write callback).

the callback function must return the size of the data it obtained. If the size of the returned data is inconsistent with the size of the data passed to it, Libcurl terminates the operation and returns an error code.

size_t helloworld::write_data (void *buffer, size_t size, size_t nmemb, void *userp) {log ("%s", (char*) buffer); return size * NMEMB; Be sure to return the number of bytes actually returned}

Code changed to size * Nmemb, NMEMB represents the size of the module, a number of modules!!!

Video Pits Ah ... Tangled dead me, fortunately finally solved!

    cocos2dx< Span style= "Color:rgb (255,0,0); Font-family:tahoma, Arial, ' song-Body '; Font-size:14px;line-height:26px;background-color: RGB (255,255,255); " > to curl is encapsulated, providing cchttpclient class, recommended that everyone use cchttpclient class, cchttpclient is asynchronous. And curl write asynchronous also need to write yourself ... Let's not build the wheels again!

Just write so much and look forward to the next article!

If there are deficiencies, please point out that together to exchange growth!

This article is from the "Little Wolf zer" blog, please make sure to keep this source http://9151482.blog.51cto.com/9141482/1586066

Cocos2dx 3.3rc0 Diary (i)------Weak networking Curl

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.