cocos2d-x + nodejs for multiplayer

cocos2d-x + nodejs for multiplayer
0.0 0


Is it possible to use multiplayer with nodeJS using cocos2d-x C++? Has anyone tried it?


Yes it’s possible by using libCURL and any webserver technology. We are developing our multiplayer game using .NET MVC4 and so far works great.


Thanks for the reply!

I am not familiar with libCURL. How is it related to nodeJS? Do you know any reference tutorial on how to do this? Thanks! :slight_smile:


libCURL is a library for URL transfer supporting lots of protocols that is bundled with cocos2d-x. Basically it will allow you to load content from RUL through HTTP protocol. This is why I said the server technology does not matter. There is a curlTest in tests in that you can check out or a code something like this:

size_t writter(void *data, size_t sz, size_t mb, char *stream)
     std::string buf = std::string(static_cast(data), sz * mb);
     return sz * emb;

char *getData(CURL* curl_handle, char *url)
    char buf[32000];
    curl_easy_setopt(curl_handle, CURLOPT_URL, url);
    curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
    curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1);
    curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
    curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, &buf);
    return strdup(buf);

init CURL like this:

CURL *curl_handle;
curl_handle = curl_easy_init();

get data from url like this:

long getServerTime()
     auto res=getData(curl_handle, SERVER_URL("server/gettime"));
     long tm=atol(res);
     return tm;

release like this:


Hope this helps


nice! Thank you so much! I will test this ASAP. :slight_smile:


I tried the code on this link

It runs fine. However, when I changed “” to “”, it logs:

@code: 7@


I’m using Windows 7 running XAMPP (Apache). I’m running the app using my galaxy Note device. My PC and device is connected to the same WIFI.
I also added this to AndroidManifest.xml

test.php only contains:

so I’m expecting the program to log “test”.

What is wrong with my code? Anyone? TIA!


Looks like will only work on emulator.

I tried the IP of my PC given by the router using ipconfig in cmd and it worked! :smiley: