how to use socket in js binding

We know,It is luasocket in lua binding.
but, how do in js binding?
the network game must be think.

You have to bind sockets library of Android or iOS to Javascript.

I’m looking around because I require this also. You might wanna checkout http://socket.io

oh,It is a difficult work for me.
I am not c++ programer, I just know a little script code.
and so,socket.io dont support windows?

socket.io will work on the browser (cocos2d-html5), but not on the js-bindings… as it requires the browser’s networking layer. I think at some point we can emulate that… Some time ago I wrote a very simple layer for emulating XMLHttpRequest, maybe someone can do the same with a more complete version. If cocos2d-x had a networking layer, we could easily wrap it automatically (the same way we’re wrapping the rest of cocos2d-x) for it to be used in javascript.

Rolando

I think the better way is to add a wrapper on both XMLHttpRequest and libcurl to fit the requirement.

We’ve written a small wrapper object around cocos2d::extension::CCHttpRequest and then generated JS bindings from this. It’s then a simple API to work with at the JS level. However, a cross-platform (including HTML5) would be better in the long run.

There is a working XMLHttpRequest for local requests here:


Remote requests (http & https, including async requests) are going to be added soon. Those two files are depending on a set of macros defined here:

I think at some point I’ll add those two to the current jsbindings in cocos2d-x :slight_smile: