How can I connect to a nodejs socket.io server from a cocos2djs game? I've google all the way to no avail. I tried this but it does not work:

socket = io.connect('');
if ( socket === undefined ) {
    cc.log("Could not connect to socket.io");
} else {
    socket.on('connect', function() {
        socket.emit('join', {username: 'Android Application'})

I read in the docs that there's a module called SocketIO for doing that, but there's not enough info on how to use it. Thanks in advance.

  • \$\begingroup\$ So what is the result? undefined or some other error? \$\endgroup\$ – Katu Apr 23 '15 at 17:32
  • \$\begingroup\$ SocketIO undefined, after searching more I found out that the dev team did not expose SocketIO from cpp to js yet as they did with the other cocos2dx components. A little discuss here: discuss.cocos2d-x.org/t/does-jsb-support-socket-io/10259/4 . I also a found a similar discussion on github, but I cant find it again. \$\endgroup\$ – Anderson Madeira Apr 24 '15 at 19:46
  • \$\begingroup\$ What stops you from writing your own networking system? \$\endgroup\$ – Bálint Dec 5 '16 at 14:45

try opening a new thread like in this video tut and use that for your connections. https://www.youtube.com/watch?v=6G_W54zuadg

there may be some useful info in this video hope it helps

  • \$\begingroup\$ Thanks, but as you can read in my question, thats not exactly what I am looking for. \$\endgroup\$ – Anderson Madeira Apr 23 '15 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.