Advertisement

Raknet prob

Started by February 16, 2005 11:22 PM
4 comments, last by Kavana 20 years ago
I'm new to raknet, I seem to get garbage when i send a packet to the server containing a struct. Anyone know what the problem is? I would be very grateful. Oh yea also with #pragma pack(1) or without it sill gives me the same thing Struct

struct NetPlayer
{
	char	playerName[20];
	int		playerHP;
	bool	alive;	
	int		playerNo;	//haven't put it yet

	core::vector3df loc;
};


Client Side

void NetworkInterface::createPlayer(char name[20],core::vector3df loc)
{			
		NetPlayer netPlayer;


                netPlayer.playerNo=0
		netPlayer.alive=true;
		netPlayer.playerHP=100;
		netPlayer.loc=loc;
		strcpy(netPlayer.playerName,name);
		rakClient->Send((char *) &netPlayer, sizeof(NetPlayer), HIGH_PRIORITY, RELIABLE, 0); 


Server Side

void NetworkInterface::processMessage(Packet *packet)
{	
	NetPlayer * tmp = (NetPlayer*)packet->data;
	printf("%d",tmp->playerNo); //Still prints out gibberishs

[Edited by - Kavana on February 17, 2005 12:22:59 AM]
set 'playerNo' to some value like 0 on the client side before you send it.. or have you initialized it elswhere?
Advertisement
Well, you didn't initialize the variable for one thing...

Try adding
netPlayer.playerNo = 100;
in the second box...
--m_nPostCount++

ok I'll just edit the code so it doesn't confuse anyone, still having werid problems though, when i print out the value for playerHp I get 3408696 for the playerNo I get 1244892
Quote:

printf("%d",&(tmp->playerNo));



Why are you printing the address of the playerNo, when you actually want the value?

Also, when you have these kinds of problems, stop the program with a breakpoint in the spot where the data is sent and received, and verify the data with the debugger. printf() should be saved for those hard-to-catch issues where you just can't stop things because they wouldn't happen (usually, real time is involved).
enum Bool { True, False, FileNotFound };
yes my bad, changed the things but still get strange numbers

This topic is closed to new replies.

Advertisement