Page 1 of 16

irrNetLite 2.1 [BETA]

Posted: Mon Jul 02, 2007 6:30 pm
by BlindSide
UPDATE: New 2.1 Beta version includes:

- Support for different w_char sizes across different machines (Linux and windows can communicate w_char now).
- More helper functions for SPacket.
- MSVC lib compiled properly now.
- Can run along side Irrlicht easily by defining "COMPILE_WITH_IRRLICHT", it will use the Irrlicht containers in this scenario. Otherwise you can also use it without Irrlicht if you want.

Hey guys I decided to release the Beta version which I've been handing around publically.

irrNetLite is an easy to use version of irrNet that does not depend on the irrlicht device or scene nodes. It is purely for easy, no hassle sending of packets using common irrlicht types.

New features in 2.0 include zlib packet compression, an AES encryption/decryption mechanism, more callbacks (For things like On connect/On disconnect) and more or less a complete re-write of the original irrNetLite.

You can get it from here:
http://irrlichtirc.g0dsoft.com/BlindSid ... .1Beta.zip

Excerpt from the tutorial (Updated API, pay attention):

Code: Select all

			// To send a packet, first you create an SOutPacket object.
			net::SOutPacket packet;
			
			// Then you can use the streaming operator << to add new data to it.
			packet << "Help I am stuck on a mountain!";
			
			// You can even chain the << operators like so, just like with ostream.
			packet << core::vector3df(50.0f, 30.0f, 20.0f) << 50.0f;
			
			// Compress the packet, not much to be said.
			packet.compressPacket();
			
			// Encrypt the packet. Note that here we are just using a simple key
			// that is shared among the client and the server. In more sophisticated
			// implementations you may want to generate a random key on the server for
			// each client and send that using a shared key, then use the new key for
			// further communication. Remember that the key should be 16 characters
			// long, and obviously the client and server must share the same key.
			packet.encryptPacket("hushthisissecret");
			
			// A simple call to "sendOutPacket" will send the packet to the server.
			netManager->sendOutPacket(packet);
Some more info (From original old post):
Most of the usage is similar to this and easy to use. It uses an interface very similar to the irrlicht event reciever, where the you construct a "packet handler" class derived from the base packet handler class and irrNetLite will send all the recieved packets there for processing. irrNetLite is not very big or elaborate, but I think it will help many people who want a no hassle solution to sending and managing their own packets without all the useless overhead and junk contained in irrNet, RakNet, and other big network libs, but also without needing to work with difficult low level api offered by Enet, HawkNL and other low level libraries.

Cheers.

Posted: Mon Jul 02, 2007 6:35 pm
by m_krzywy
Looks nice. I'll try it in practise ;)

Posted: Tue Jul 03, 2007 10:12 am
by 3ddev
Quite nice. Easy to integrate with existing games. :wink:

Posted: Tue Jul 03, 2007 10:44 am
by omar shaaban
ya that was what i looking for !!! not on irrlicht scene node who i couldn't understand it or seemed stupid to me but this is perfect a simple network !! thanks blind side !!

Posted: Tue Jul 03, 2007 5:39 pm
by stef_
IMHO the name is a bit wrong, should be : enetUtils, enetPacketBuilder.

A wrapper should add something a bit more consistent, otherwise I prefer to use
enet directly :)

Bye

Posted: Tue Jul 03, 2007 5:45 pm
by BlindSide
stef_ wrote:IMHO the name is a bit wrong, should be : enetUtils, enetPacketBuilder.

A wrapper should add something a bit more consistent, otherwise I prefer to use
enet directly :)

Bye
Yes I recommend people to use ENet directly to have more control. But if someone wants to use this so its easier then they can too.

Posted: Thu Apr 03, 2008 1:53 pm
by lostclimategames
this is nice but my question would be is how did you accomplish this. I want to make my own packet handling system that can send and recieve instances of classes I made in my program, an was wondering how you got this to work.

Posted: Thu Apr 03, 2008 8:58 pm
by d3jake
Is this version tied to Windows and Linux? Or can it be compiled on Mac as well? Forgive me if the other one does indeed work on Mac...

Posted: Thu Apr 03, 2008 9:04 pm
by monkeycracks
Just curious, I was trying to implement a disconnect() function for the client. I did so in INetManager like this :

Code: Select all

void INetManager::disconnect()
		{
			if(!isserver)
				enet_peer_disconnect(peer, 0);
		}
Is this correct? Should I be doing it differently? How could I disconnect a client from the server based on the client id?

I looked through the eNet docs and tried to play around with the irrNetLite stuff to make it work but I'm still not getting the printf that should be showing when ENET_EVENT_TYPE_DISCONNECT is given.

Posted: Thu Apr 03, 2008 9:32 pm
by MasterGod
Pure simplicity. I love it.
Thanks!!

P.S
Add a link in the Wiki..

Posted: Fri Apr 04, 2008 5:27 am
by BlindSide
monkeycracks wrote:Just curious, I was trying to implement a disconnect() function for the client. I did so in INetManager like this :

Code: Select all

I looked through the eNet docs and tried to play around with the irrNetLite stuff to make it work but I'm still not getting the printf that should be showing when ENET_EVENT_TYPE_DISCONNECT is given.[/quote]

I think thats correct, I'll have a closer look into it later. The manager automatically calls enet_deinitialize(); when its destructed, so you can just destroy the NetMgr when you want to disconnect, and make a new one when you want to make a new connection. (Unless there is some specific reason why you can't do this.).

I also implemented an onConnect callback for this, as I found that essential, and a few other improvements. So expect those to be added sometime soon.

[quote]this is nice but my question would be is how did you accomplish this.[/quote]

Well I thought you could look at the source of irrNetLite and figure that out. Hint "memcpy".

[quote]Is this version tied to Windows and Linux? Or can it be compiled on Mac as well? Forgive me if the other one does indeed work on Mac...[/quote]

In theory it'll work without a flaw on Mac, as it just uses Enet which just uses BSD sockets which are implemented pretty identically on both Unix and Mac operating systems. Googling for something like "Enet on Mac" should get you somewhere if you're stuck. [url=http://lists.puremagic.com/pipermail/enet-discuss/2004-August/000254.html]This post seems relevant.[/url]

Posted: Sat May 03, 2008 2:16 pm
by D-Eagle
My server crashes, when second player joins and tries to send a packet.

Code: Select all

#include "irrNet.h"

#pragma comment(lib,"ws2_32.lib")

using namespace irr::net;

INetManager* NetManager;

class CPacketHandler : public PacketHandler
{
public:
    CPacketHandler(){};
    virtual ~CPacketHandler(void){};
    virtual void Handle(InPacket * packet);
private:
	char buffer[1000];
	c8 packetid;
};

void CPacketHandler::Handle(InPacket * packet)
{
	packet->getNextItem(packetid);

	if(packetid == 50)
	{
		packet->getNextItem((char*)buffer);
		c8 textstyle; packet->getNextItem(textstyle);
		OutPacket* opacket = NetManager->createOutPacket();
		opacket->addData((c8)50);
		opacket->addData(buffer);
		opacket->addData(textstyle);
		for(u16 i=0;i<NetManager->getPeerCount();i++)
		{	
			NetManager->sendOutPacket(opacket,i);
		}
		printf("%s \n",buffer);
	}
}

int main()
{
	CPacketHandler* handler = new CPacketHandler();
	NetManager = createNetManager(handler);
	NetManager->setUpServer(2593);

	while(1)
	{
		NetManager->update();
	}

	return 1;
}
the console:

Code: Select all

Initializing Enet!
Creating server!
A new client connected from 100007f:1951
asd: mo
asd: this works
asd: let me join with another client
A new client connected from 100007f:1952
asd2: hi
Error sending outgoing packets: No error
Error sending outgoing packets: No error
Error sending outgoing packets: No error
Error sending outgoing packets: No error
Error sending outgoing packets: No error
Error sending outgoing packets: No error

Posted: Mon May 05, 2008 2:05 am
by BlindSide
You are probably calling update() too frequantly. This is designed to be used in a game loop, so stick a "Sleep(100);" in there just after "NetManager->update();".

Posted: Mon May 05, 2008 1:14 pm
by D-Eagle
I added it to the server, and it still does it.

Posted: Fri May 09, 2008 11:46 pm
by BlindSide
Ok another problem I see is:

Code: Select all

for(u16 i=0;i<NetManager->getPeerCount();i++)
      {   
         NetManager->sendOutPacket(opacket,i);
      } 
Could you try replacing it with:

Code: Select all

NetManager->sendOutPacket(opacket);
Which does the exact same thing.

Does the debugger tell you anything useful?