// Create a bitstream object RakNet::BitStream bs; // Write some data into the BitStream int playerID = 1; bs.Write(playerID); float posX = 10.0f; float posY = 20.0f; float posZ = 30.0f; bs.Write(posX); bs.Write(posY); bs.Write(posZ); // Send the BitStream over network RakNet::SystemAddress recipient = ...; RakNet::RakPeerInterface* pPeer = ...; pPeer->Send(&bs, HIGH_PRIORITY, RELIABLE_ORDERED, 0, recipient, false);
// Create a bitstream object containing received data RakNet::BitStream bs(packet->data, packet->length, false); // Read data from the BitStream int playerID; bs.Read(playerID); float posX, posY, posZ; bs.Read(posX); bs.Read(posY); bs.Read(posZ); // Use the data for further processing movePlayer(playerID, posX, posY, posZ);In the first example, we create a BitStream object and write some data into it. We then use the RakNet peer interface to send the BitStream over the network to a specified recipient. In the second example, we receive a packet of data and create a BitStream object containing the data. We then read the data from the BitStream and use it to update the position of a player in the game.