PDA

View Full Version : RakNet: How to receive bitstream packets of different sizes?


Weng
11-19-2008, 06:54 PM
I am using Raknet to develop the multiplayer component of an RPG game.

Currently, when receiving packets, I treat all bitstream packets to be of the same size.

e.g.

p = server->Receive(); //p is a packet* type
BitStream bs(p->data,(sizeof(int)+sizeof(int)+sizeof(int),false);
bs.Read(message);

if(message == NEW_POSITION)
{
playerStruct player; //a structure for storing position

bs.Read(player.x);
bs.Read(player.y);
bs.Read(player.z);
}

How do I accept different bitstream packets of different sizes?

Reedbeta
11-19-2008, 07:12 PM
Googling for "RakNet packet" brought up this article (http://www.jenkinssoftware.com/raknet/manual/Doxygen/html/structPacket.html) in the RakNet docs.

In particular, the packet struct has a 'length' member that tells you how many bytes are in the packet. Just pass this to the BitStream constructor.