Game Development Reference
In-Depth Information
// Do something with the received data, on the
main thread
[[NSOperationQueue mainQueue]
addOperationWithBlock:^{
// Process the data
unsigned char *incomingPacket = (unsigned char
*)[data bytes];
int *pIntData = (int *)&incomingPacket[0];
NetworkPacketCode packetCode =
(NetworkPacketCode)pIntData[1];
switch( packetCode ) {
case KNetworkPacketCodePlayerAllotment:
{
NSInteger gameUniqueId =
pIntData[2];
if (gameUniqueIdForPlayerAllocation >
gameUniqueId)
{
self.gameInfoLabel.text =
kFirstPlayerLabelText;
}
else
{
self.gameInfoLabel.text =
kSecondPlayerLabelText;
}
break;
}
default:
break;
}
}];
}
While receiving the data, it should be processed on a mainQueue operation
block. In this block, we will remove the header in the pIntData pointer vari-
able and get the NetworkPacketCode sent in the packet. In this code, we will
check the type of packet which is sent. Then we will parse the packet based on its
Search WWH ::




Custom Search