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