Starting RakNet

RakPeerInterface::Startup( unsigned short maxConnections, int _threadSleepTimer, SocketDescriptor *socketDescriptors, unsigned socketDescriptorCount ) The first thing you should do is call RakPeerInterface::Startup(). Startup() will Generate RakNetGUID, a unique identifier identifying this instance of RakPeerInterface. You can get it with RakNetGUID g = rakPeer->GetGuidFromSystemAddress(UNASSIGNED_SYSTEM_ADDRESS); Allocate an array of reliable connection slots, defined by the maxConnections parameter. This may be the maximum number of players for your game, or you may want to allocate extra to keep some buffer slots open, and manually control who enters your game or not. Create 1 or more sockets, described by the socketDescriptors parameter Before calling Startup(), generally only raw UDP functions are available, including Ping(), AdvertiseSystem() and SendOutOfBand(). _threadSleepTimer The thread sleep timer controls how long RakNet will sleep between each internal update in its thread. A value of 0 will cause it to yield thread access after running once, then run again once its thread is scheduled again. This is suitable for file transfers over very low ping networks. It can also be used for games to save off a small amount of ping. However, Windows will report substantially more CPU usage. Many users are alarmed by this: However, keep in mind that the thread will yield, so if your game is doing other things, it won't slow down your game. If you don't want to use a value of 0, a value of 30 greatly reduces idle CPU usage. Idle CPU Usage in BigPacketTest
30 Sleep Timer | 0 Sleep Timer
socketDescriptors parameter In 95% of the cases, you can pass something like: SocketDescriptor(MY_LOCAL_PORT, 0); For MY_LOCAL_PORT, if running a server or peer, you must set this to whatever port you want the server or peer to run on. This is the remotePort parameter you will pass to Connect(). If running a client, you can set it if you want to, or use 0 to automatically pick a free port. However, you can also create an array of socket descriptors: SocketDescriptor sdArray[2]; sdArray[0].port=SERVER_PORT_1; strcpy(sdArray[0].hostAddress, "192.168.0.1"); sdArray[1].port=SERVER_PORT_2; strcpy(sdArray[1].hostAddress, "192.168.0.2"); if (rakPeer->Startup( 32, 30, &sdArray, 2 ) OnRakNetStarted(); This is for advanced users that want to bind multiple network cards. For example one card to go to the secure server behind the LAN, and another to the internet. To access the different bindings, you would pass the index of the binding to use to functions in RakPeerInterface that have a connectionSocketIndex parameter.

See Also

Index FAQ