Facing problem with websockets in cocos2d-x-2.1.5

Facing problem with websockets in cocos2d-x-2.1.5
0.0 0



When i try to create a websocket connection to echo.websocket.org, it succeeds and the onOpen() callback is triggered but when i try to point to my own socket.io based server, i never get the callback. Have tried putting breakpoints in Websocket.cpp and case LWS_CALLBACK_CLIENT_ESTABLISHED never gets triggered in Websocket::onSocketCallback().

Am I missing something?


Figured out that socket.io handshake is bit complex and needs a compatible client (libwebsocket doesnt seem to be). Has anyone tried libwebsockets with Golang websockets? I tried with the defautl websocket plugin in golang and it doesnt seem to work. Any other workarounds for golang server and libwebsocket client?


The websockets were only recently added to the codebase, I don’t think we should be too exited yet.

Has anyone had success with connection via cocos Websocket to a Websocket server?


yeah. It works fine with NodeJS ws library which is what i am exploring as of now.


But NodeJs is an Html/Web library, cant use that with Native/C++, right?


Socket.io sits on top of websockets and has its own protocol, the specs for which you can find here: https://github.com/LearnBoost/socket.io-spec


To download the libwebsocket’s source code, compile and replace cocos2dx’s libwebsocket

git clone git://git.libwebsockets.org/libwebsockets