后端使用NodeJS监听同一个端口对外提供Http以及SocketIO协议的通信服务,根据chatConfig.json配置的不同,NodeJS与前端的序列化协议可使用protobuf或者json
而前端客户端也根据chatConfig.json配置的不同,提供了cocos2d-js或者http(其实叫html更好)的客户端;具体描述以及截图请看下面(力不从心使用了蹩脚的英文描述,应该差不多都能看得懂吧,有语法错误也劳驾指正)
本例是基于SocketIO协议长连接的,而基于Http协议短连接的更纯粹使用Cocos2d-JS/Ajax+protobuf+NodeJS/Java Spring MVC的例子请看Cocos2d-JS-Protobuf和cocos2d-js-ajax-protobuf-nodejs-springmvc
frontend(Cocos2d-JS/Html/RequireJS) communicate with backend(NodeJS/Java) by Http/SocketIO/Protobuf/Json protocol to implements Chat
- Set up dependencies:
npm install
- Copy the cocos2d-js
frameworks
to frontend/cocos2d-js directory - Make sure the backendType is
nodejs
inchatConfig.json
- Change Directory to backend/nodejs
cd backend/nodejs
- Run:
node server.js
- Open
http://localhost:3000
in a recent browser
Instructions for Java/Netty-socketio
- Install JDK/JRE 1.7+
- Install Maven 2.2+
- Run:
mvn -f backend/java/pom.xml clean compile
it will take a long time to download and set up dependencies jar packages - Make sure the backendType is
java
inchatConfig.json
- Change Directory to backend/nodejs
cd backend/nodejs
- Run:
node server.js
- Open
http://localhost:3000
in a recent browser
you can edit chatConfig.json to choose What You Want To Run as below:
frontend type (client) | chat type (serialization protocol) | backend type (server) |
---|---|---|
http | json | nodejs |
http | protobuf | nodejs |
coco2d-js | json | nodejs |
coco2d-js | protobuf | nodejs |
http | json | java |
http | protobuf | java |
coco2d-js | json | java |
coco2d-js | protobuf | java |
frontend is cocos2d-js And chat serialization protocol is protobuf
you can use /name [user name] command to changed your name
you can use /join [room name] command to create/join another room
frontend is http(actually html is a better name) And chat serialization protocol is json
2016.4.27 use netty-socketio to Make Java backend
2016.4.28 use NodeJS(child_process module & maven command) to start Java backend server, now you can edit backendType[nodejs/java]
in chatConfig.json
:
{
"frontendType" : "http",
"chatType" : "protobuf",
"backendType" : "nodejs"
}