Currently porting my multiplayer game from Cocos2d (Objective-C) to Cocos2dx (C++).
In Cocos2d i used platform dependent Sockets and it is impossible to port this part of code to C++, i am not from C++ world,
so i appeal to you: please help me to implement some code.
My needs is next:
change Sockets to Receive data in another thread using infinite loop and then send data to Delegate.
I’m doing some work with a couple of cocos2d-x network related clases, like cocos2d::network::HttpRequest and cocos2d::network::HttpResponse, maybe you can see my example here:
If this helps you please let me know if you have any question.
no it can not help me, because HTTP is based on low level Socket programming and source hidden somewhere and i need this low level.
anyway i don’t know how to programming Threads in C++.
request->setRequestType(cocos2d::network::HttpRequest::Type::GET);
request->setResponseCallback(CC_CALLBACK_2(COTDGoogle::onHttpRequestCompleted, this));
request->setTag("GET Google COTD");
cocos2d::network::HttpClient::getInstance()->send(request);
request->release();
And then capture the response, right? Using a call back COTDGoogle::onHttpRequestCompleted:
This works asynchronously so you can add a spinner or block somehow the UI and wait for the response in the callback method.
Another possibility is try to CURL, but I don’t understand how do you work with sockets in cocos2d, and the type of code you are migrating, because with cocos2d you can use the regular iOS frameworks, AFNetworking for example.
thank you, but looks like you dont understand the difference between low levele socket and websocket (Sorry I did not mean to offend you).
you suggest use websockets, but it is not my way, server writen with binary stream low level socket and works correctly, i dont want to write a lot of code to support WebSockets.
i also try to use Poco but there is problems with usage (no body knows how to use it) one, two
to understand me correct i try so explain:
between client and server i send Protobuf messages;
Protobuf gives me full controlled protocol;
Protobuf can be serialized to binary then i can send it to server via socket where this message will be deserialized;
dont know what genre is, maybe arcade, my game is based on movie “13” by Gela Babluani, this movie is about Russian Roulette.
Apple blocked my game in case of “Guideline rules”, so i ported it to Android with Cocos2dx, looks like there is a lof of Russian Roulettes but my will be Real roulette with multiplayer.
looks like i forgot to answer to your question “In what genre game is, that there is needed such functionality”:
every time you play multiplayer game - know, it is using low level sockets (need for speed, world of warcraft, world of tanks, counter strike etc)