Jump to content


RakNet: How to receive bitstream packets of different sizes?


1 reply to this topic

#1 Weng

    New Member

  • Members
  • PipPip
  • 16 posts

Posted 20 November 2008 - 02:54 AM

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?

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 20 November 2008 - 03:12 AM

Googling for "RakNet packet" brought up this article 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.
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users