RakNet plugin for easy client/server networking

Hey Folks,

some time ago i made a C++ plugin which integrates an easy interface to RakNet (C++ UDP networking library). I wondered if there is interest in the community for this?

To make it short here are some examples how to use it in Unity’s C#:

Here we start a server and a client which connects to it (if server started successfully) on one machine:

if( false == GabNetAP.IsServer()  false == GabNetAP.IsClient() )
{
	// 32 players max., port 1234
	if( GabNetAP.StartServer( 32, 1234 ) )
	{
		GabNetAP.StartClient( "localhost", 1234 );
	}
}

This is how the client sends some packets (the server would do it quite the same):

GabNetAP.NewOutPacket( GabNetAP.eMsgID.ID_MSG_CS_TEST, true, GabNetAP.fromClient );

byte testbyte = 4;
GabNetAP.AddByteToOutPacket( testbyte ); // there are functions for: byte, short, int, string, float ....

// "-1": client id isnt neccessary for clients (they always send to server) - server would define receiver with this arg
GabNetAP.SendOutPacket( GabNetAP.ePriority.MEDIUM, GabNetAP.eReliability.UNRELIABLE, -1 );

This is how the server would read this package (the client would do it quite the same):

int serverPacketCount = GabNetAP.GetPacketCount( GabNetAP.fromServer );
for( int i=0; i<serverPacketCount; ++i )
{
	switch( (GabNetAP.eMsgID)GabNetAP.GetMessageIdFromPacket( i, GabNetAP.fromServer ) )
	{
		case GabNetAP.eMsgID.ID_MSG_CS_TEST:
			{
				// this is standard info sent with the packet
				short clientId 		= GabNetAP.GetClientIdFromPacket( i, GabNetAP.fromServer );
				double timestamp 	= GabNetAP.GetTimestampFromPacket( i, GabNetAP.fromServer );
				
				// custom packet info (this is what we added on the client)
				byte testbyte = GabNetAP.GetByteFromPacket( i, GabNetAP.fromServer );
			}
			break;

	}
}

Of course there are also some helper functions like:
// am i a server ?
GabNetAP.IsServer()
// and/or am i client which has an open connection to a server?
GabNetAP.IsClientConnected()
// oooor am i client which still waits for the server to respond to his connection attempt?
GabNetAP.IsClient()

… and many more.

I optimized all internal packeting and stuff for maximum speed and minimum packet size. All clients automatically get a client id from the server for their session, which is needed for the communication.

If there is enough interest i might release the full C++ source and the unity3d stuff as product in the Asset Store or on my shop (see signature) or both … :wink:
(This wouldnt include a RakNet licence though)

… anyone?

Cheers
Ethan

What would be the advantage to using this over the built-in networking’s RakNet? (Serious question, I don’t know much about the nuts and bolts of networking)

Hi legend411!

Unity’s internal networking isn’t really optimized for speed and/or many users and has some serious bugs.
I made BlobFoot with Unity’s networking and it went bad on some points because of known issues (search the forums for “unities networking is disfunctional”)

This is why i started this approach - to be independent of Unity in networking. :slight_smile:

Cheers
Ethan

I’d be interested in utilizing this should you release it.

This would be interesting to me as well. Although I already have the client-server architecture running on default Unity networking. I think we might need some extendability. And I am not extremely well versed in Networking, but one thing I know we would need for an option we are exploring is binding a headless instance to a specific IP. Would this be something that your plug in can accomplish? or that we could add in with your plug in?

Again, I am not extremely knowledgeable about networking, but this is what the hosting service informed me. Due to the virtualization of their servers, they initialize based on IP.

Or am I missing something that is already there?

Hey Echo,

what do you mean with “binding a headless instance to an ip”? If you start any server it is bound to the ip of the server, isn’t it?

Cheers
e

I guess what he means is that if you have a server where you have more than 1 network interface, you can tell the headless server which of those network interfaces and thus IP its meant to use

Does your package have any support for fault tollerance/predictive handling client side?

Cheers,

Galen

@Echofiend: i didn’t really handle that case. At the moment i am just opening a server on a specific port.

@Galent: The plugin itself doesn’t do that, because it only handles basic navigation. But i made a shooter prototype with the plugin which integrates all the rules from this article: http://gafferongames.com/game-physics/networked-physics/

Cheers
e

Hi Ethan, Ya to answer your question I need to be able to tell the headless client which IP address to use. Dreamora was correct in his post above.

Well in that case, I might start need to start another thread to see if there is a way to tell the headless client which IP to run on.