IrrNetLite Packet Handling[solution reached]

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
ortsa
Posts: 11
Joined: Sun Jul 27, 2008 4:14 pm

IrrNetLite Packet Handling[solution reached]

Post by ortsa »

Hey,
Iv just started using IrrNetLite and networking in general

Iv been making a client and server but iv run into problems with sending and recieving packets, the client can connect to the server with no problems but when i try to send a packet the server never receives it

This is the code im using

Client

Code: Select all

void Login(stringc username, stringc password)
{
net::OutPacket* LoginPacket = netMgr->createOutPacket();
	
c8 packetId = 50;

LoginPacket->addData(packetId);
LoginPacket->addData(username.c_str());
LoginPacket->addData(password.c_str());

netMgr->sendOutPacketUnreliable(LoginPacket);
}
And for the server

Code: Select all

NetworkClass::Handle(irr::net::InPacket * packet) 
{
	c8 packetid;
	char* buffer[1000];

	packet->resetPos();

	packet->getNextItem(packetid);

	if(packetid == 50)
	{
		packet->getNextItem((char*)buffer);
		cout << (char*)buffer << endl;
		packet->getNextItem((char*)buffer);
		cout << (char*)buffer << endl;
	}
}
Any help would be appreciated :)
Last edited by ortsa on Wed Jul 30, 2008 1:10 pm, edited 1 time in total.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

maybe unrelated, but......


shouldnt
char* buffer[1000];
be
char buffer[1000];


also, put some debugging info in there to see what is happening...

NetworkClass::Handle(irr::net::InPacket * packet)
{
printf("Handle()\n");
if (packet!=NULL) printf("Handle is valid\n");

c8 packetid;
char* buffer[1000];

packet->resetPos();

packet->getNextItem(packetid);

printf("checking if packet ID == 50\n");
if(packetid == 50)
{
printf("packet ID is 50\n");
packet->getNextItem((char*)buffer);
cout << (char*)buffer << endl;
packet->getNextItem((char*)buffer);
cout << (char*)buffer << endl;
}
else printf("packet ID is NOT 50\n");

}
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

Note: If you send out a packet unreliably, there is no guarantee your server will ever receive that packet. For something like a login packet, why don't you send it reliably so you know that it'll get there eventually.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
ortsa
Posts: 11
Joined: Sun Jul 27, 2008 4:14 pm

Post by ortsa »

Found the source of the problem, rather stupid - i forgot to put update in the clients loop :oops:

Note: If you send out a packet unreliably, there is no guarantee your server will ever receive that packet. For something like a login packet, why don't you send it reliably so you know that it'll get there eventually.
Yeah thats because i was just trying it out to see if it would make a difference.
shouldnt
char* buffer[1000];
be
char buffer[1000];
I dont know but thats what was being used in some tutorials i read on these forums
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

ortsa wrote:
shouldnt
char* buffer[1000];
be
char buffer[1000];
I dont know but thats what was being used in some tutorials i read on these forums
:shock: It shouldn't be "char*". I would appreciate it if you can point out where you found this, since it will be best if I fix it right away.

PS: I replied to your pm a few days ago but it still hasn't sent, the forum's pm system can be a bit screwy.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Post Reply