Quick COCOS2DX HTTP Communication

Source: Internet
Author: User

Service side: Python

Communication protocol: HTTP Reference article: 1 implement a basic HTTP server server in Python HTTP://BLOG.SINA.COM.CN/S/BLOG_416E30630100GJYK.HTML2// Stackoverflow.com/questions/8470414/strange-jquery-error-code-501-message-unsupported-method-options Because it is done according to the idea of the legend of the turret, the legend of the turret does not need to be connected frequently, so use HTTP as the communication protocol. The Python server is looking for the following code: When you press F11 in Eclipse, you can see the service start in the console: Quick cocos2dx, Just follow the example of the createhttprequest in the Network.lua file, and create a new class as follows: Then add its reference in MyApp and provide the interface, as a singleton: after that, in order to test whether it is available, In the Mainscene.onenter method, add the test code, as follows: Refresh the player, and then you will see the server response: The client also error: At this point, the communication test initial success, although the error. Server problems, search for a bit, is their own code to write a problem, the new code is as follows: When reconnecting the test, you will see the console there is no error.
200 represents the return success. Now, only the client is still in error. The client problem has also been resolved, the callback method is changed to the local method: Now, the client will not error, but the information received is still problematic:
Careful observation, found the bottom of the log information is completed, so should be the result of their own clerical error, modified, the final callback function code as follows: And then refresh again, impressively can see the server returned text: Follow-up study using JSON serialization object, and encrypted with text such as AES or BASE64. The end of this article.

Quick COCOS2DX HTTP Communication

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.