How to using with cocos2d-x

How to using with cocos2d-x
0.0 0


Hi everyone!
I am developing a multiplayer game using cocos2d-x html5 version.
The server are writing in nodejs so my question is how can i using inside cocos2d-x code?
Can you please provide some line of code or separate class for implements this?


hi taka,

I have working successfully on the server side with node.js and on the client side within the cocos2d-html5 framework. An example implementation is in my repo at:

You only need a couple lines of code, instructions are below.

In your html file add the script, this is served dynamically if you have the node.js module running, there is no need to actually create a ‘’ directory

<script src="/"></script>

In your cocos2d app add this line (you can place this in your layer’s init, or create a helper class):

this.socket = io.connect('http://path:port');

to verify, add a simple handler:

this.socket.on('connect', function() { console.log('connected!')});

Hope this helps. I also had some issues setting up the newest version of Express with, if you need help with the server side code the key is here: = require('express'), this.server =, = this.server.listen({port number}), this.iolib = require('');

@ = this.iolib.listen(;@

this.server is your Express server, is the module, and would be used for communication


Thanks so much! You are my hero:)


Oh, Chris Hannon, you are also my hero Thank you!


Is this working for socketio 1.0?


It’s seem not work for scocketio 1.0, I’m face this issue and stuck at this point.


When do i build code to Android or IOS. this Socket work?