We’ve added support for UDP messaging in our latest Cocos2dx SDK update!
The ability to exchange game play data over UDP has been appreciated by our developer community since it was released for other platforms and was requested by many of our Cocos2dx SDK users.
Using AppWarp UDP APIs is straight forward for developers. Once you are successfully connected to the cloud server, you will need to perform the UDP handshake with the server. This is required because more often than not, the clients will be behind NATs and this requires a handshake (NAT punch through) for bi-directional connectivity to be established.
/** * Initiates the UDP handshake with the server. The result is provided in the * onInitUDPDone callback of the connection request listener. */ void initUDP();
The following diagram illustrates how the process works behind the scenes (Host B is the AppWarp server).
Once you’ve received onInitUDPDone with success, you can then use the sendUdpUpdate API to exchange binary game play data in the room.
/** * sends a custom UDP update message to room in which the user is currently * joined. No acknowledgement is received for this request. * * @param update * @param updateLen */ void sendUdpUpdate(byte* update,int updateLen);
All subscribers of the room will receive the message through the onUpdatePeersReceived callback with the parameter isUDP with value true.
virtual void onUpdatePeersReceived(AppWarp::byte update, int len, bool isUDP)
UDP is great for action based games in which the message exchange frequency is expected to be high and the inherent unreliability of protocol is acceptable. We will soon be coming up with some samples on how to use UDP in our Cocos2dx SDK.
If you have any questions or need any further assistance, please feel free to write us at firstname.lastname@example.org