Skip to content

Latest commit

 

History

History
executable file
·
31 lines (22 loc) · 786 Bytes

README.md

File metadata and controls

executable file
·
31 lines (22 loc) · 786 Bytes

CQWrap

Extensions for cocos2d-x javascript bindings.

1. WebSocket for cocos2d-x

Export websocket api in javascript for cocos2d-x javascript bindings.

based on:

[http://git.warmcat.com/cgi-bin/cgit/libwebsockets/]

[http://sourceforge.net/projects/jsoncpp/]

var host = "ws://localhost:8080/test";
var ws = new WebSocket(host,'default-protocol'); // create the web socket
ws.onopen = function () {
   cc.log("connected... ", 'success'); // we are in! :D
};

ws.onmessage = function (evt) {
   cc.log(evt.data, 'response'); // we got some data - show it omg!!
};

ws.onclose = function () {
   // the socket was closed (this could be an error or simply that there is no server)
   cc.log("Socket closed!", 'error'); 
};