cocos2d-x + nodejs for multiplayer

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:

Hi,
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);
     strcpy(stream,buf.c_str());
     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);
    curl_easy_perform(curl_handle);
    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:

curl_easy_cleanup(curl_handle);

Hope this helps

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

I tried the code on this link http://www.plungeinteractive.com/blog/internet-communications-on-cocos2d-x-with-libcurl/

It runs fine. However, when I changed “www.jesusbosch.com” to “http://10.0.2.2/test/test.php”, it logs:

@code: 7@

(7 means CURLE_COULDNT_CONNECT).

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 10.0.2.2 will only work on emulator.

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