[help]How to do network programming in cocos2d-x javascript?

Hi all,I want to do network programming with js. But I cant find any network api for js.
I know that XMLHttpRequest can be used in cocos2d-html5.And CCHttpClient can be use with c++. But what can be used in cocos2d-x js?
Is there some unified network programming api which can be used both in cocos2d-x js and cocos2d-html5?
Urgent for your any answer. Thanks very much.

XMLHttpRequest and WebSocket are both supported in cocos2d-x JSB (from v2.1.4).
You could refer to TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.

James Chen wrote:

XMLHttpRequest and WebSocket are both supported in cocos2d-x JSB (from v2.1.4).
You could refer to TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.

Thanks very much.I am using the 2.1.3 version.I will download v2.1.4 at once.

James Chen wrote:

XMLHttpRequest and WebSocket are both supported in cocos2d-x JSB (from v2.1.4).
You could refer to TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.

I used node.js and socket.io to write my server side .And the port is 1000.
And I changed the WebSocketTest address “ws://echo.websocket.org” to “ws://localhost:1000”.
But it’s not successfull .And chrome console said “Unexpected response code 301/ _wsiError websocket instance closed./_wsiSendText websocket instance closed.”
I dont know why. It’s driving me crazy. Can u help?

James Chen wrote:

XMLHttpRequest and WebSocket are both supported in cocos2d-x JSB (from v2.1.4).
You could refer to TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.

I can not find out where are directory TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.

James Chen wrote:

XMLHttpRequest and WebSocket are both supported in cocos2d-x JSB (from v2.1.4).
You could refer to TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.

john wang wrote:

James Chen wrote:
> XMLHttpRequest and WebSocket are both supported in cocos2d-x JSB (from v2.1.4).
> You could refer to TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.
>
I can not find out where are directory TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.

Download the newest version 2.1.4.Then u can find the dirs.

S lee wrote:

john wang wrote:
> James Chen wrote:
> > XMLHttpRequest and WebSocket are both supported in cocos2d-x JSB (from v2.1.4).
> > You could refer to TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.
>
> I can not find out where are directory TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.
>
Download the newest version 2.1.4.Then u can find the dirs.

I am using 2.1.4

Please refer to attached image, there is no directory TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.

john wang wrote:

S lee wrote:
> john wang wrote:
> > James Chen wrote:
> > > XMLHttpRequest and WebSocket are both supported in cocos2d-x JSB (from v2.1.4).
> > > You could refer to TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.
> >
> > I can not find out where are directory TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.
>
> Download the newest version 2.1.4.Then u can find the dirs.
>
I am using 2.1.4
>
Please refer to attached image, there is no directory TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.

oop. No these dirs. Forget to tell u that u can find network samples under “samples\tests\ExtensionsTest\NetworkTest”.lol~

S lee wrote:

john wang wrote:
> S lee wrote:
> > john wang wrote:
> > > James Chen wrote:
> > > > XMLHttpRequest and WebSocket are both supported in cocos2d-x JSB (from v2.1.4).
> > > > You could refer to TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.
> > >
> > > I can not find out where are directory TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.
> >
> > Download the newest version 2.1.4.Then u can find the dirs.
>
> I am using 2.1.4
>
> Please refer to attached image, there is no directory TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.
>
oop. No these dirs. Forget to tell u that u can find network samples under “samples estsExtensionsTestNetworkTest”.lol~

no directory samples/tests/ExtensionsTest/NetworkTest"

john wang wrote:

S lee wrote:
> john wang wrote:
> > S lee wrote:
> > > john wang wrote:
> > > > James Chen wrote:
> > > > > XMLHttpRequest and WebSocket are both supported in cocos2d-x JSB (from v2.1.4).
> > > > > You could refer to TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.
> > > >
> > > > I can not find out where are directory TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.
> > >
> > > Download the newest version 2.1.4.Then u can find the dirs.
> >
> > I am using 2.1.4
> >
> > Please refer to attached image, there is no directory TestJavascript/ExtensionTest/WebSocketTest and TestJavascript/XMLHttpRequestTest.
>
> oop. No these dirs. Forget to tell u that u can find network samples under “samples estsExtensionsTestNetworkTest”.lol~
>
no directory samples/tests/ExtensionsTest/NetworkTest"

samples/javascript/shared/tests/ExtensionTest/NetworkTest. The front dir path is available in cocos2d-html5.

Thanks I got it