服务端:Python
通讯协议:Http
参考文章:
1 用python实现一个基本的http server服务器 http://blog.sina.com.cn/s/blog_416e30630100gjyk.html
2 http://*.com/questions/8470414/strange-jquery-error-code-501-message-unsupported-method-options
由于是照着刀塔传奇的思路来做的,刀塔传奇是无需进行常连接的,所以使用Http作为通讯协议。
Python服务端在网上找的,代码如下:

在Eclipse中按下F11,就可以在控制台看到服务启动:

Quick Cocos2dx中,完全是照着network.lua文件中的createHTTPRequest的例子说明写的,新建了一个类,如下:

然后在MyApp中增加其引用并提供接口,当作单例来用:



之后,为了测试是否可用,在MainScene.onEnter方法里头加了测试代码,如下:

刷新Player,然后就会看到服务端有反应了:

客户端也报错了:

至此,通讯测试初步成功,虽然报错了。
服务器的问题,搜索了一下,是自己的代码写的有问题,新改的代码如下:

重新连接测试的时候,就会看到控制台里头没有报错了。
200代表的是返回成功。

现在,只剩下客户端还在报错了。
客户端问题也已经解决,将回调方法改为本地方法就可以了:

现在,客户端不会报错,但是收到的信息还是有问题的:

仔细观察了一下,发现了最下面一个的log信息是completed,所以应该是自己的笔误所致,修改了一下,回调函数的最终代码如下:

然后再次刷新,赫然可以看到服务端返回的文本:

后续研究一下使用JSON序列化对象,并且用AES或者BASE64之类的文本加密。
此文完结。