User:Jamestheprogrammer/RakNet
About RakNet
[edit]RakNet is a cross-platform, open-source, object-oriented networking library for C++ created by RakkarSoft. It is specialized for game development, and is available under three different licenses. It uses UDP for network communications, and supports Client/Server and P2P systems. Anyone can obtain a copy of RakNet under the GNU General Public License for free. However, linking it into your own source code, even with a static library or a DLL, would force your source code to be released under the GNU GPL, you can apply for a free Shareware or Commercial license. It is a very easy process to obtain a license. Simply fill out an easy-to-find form on the RakkarSoft website, and you'll probably receive a license sometime during the next few weeks.
Advantages Over DirectPlay
[edit]RakNet has many advantages over Microsoft's DirectPlay, the largest two being that RakNet is open-source, and that RakNet is cross-platform. However, it has a much nicer API as well. It generally takes less than an hour to integrate RakNet into a project. All you have to do is use the RakNetworkFactory class to create a RakServerInterface object in your server application, and a RakClientInterface object in your client application. If you want to use P2P, use RakPeerInterface. Looking back to DirectPlay, you have to deal with COM to create the basic interface, and then handle some mysterious structures buried deep within the DirectX SDK. And, of course, with DirectPlay, you're stuck with Windows. That would be fine for your game's client, but Linux would be a better server platform for most games, especially an MMORPG.
The Basics of Usage
[edit]As previously stated, implementing RakNet into your project is quick and easy. Create RakClientInterface and RakServerInterface objects in their respective applications to start.
Server Side
[edit]Use the Start member function of the RakServerInterface object you created to open the port and start listening for incoming connections. You can specify the port number and the maximum allowed number of players to be connected to the server at any one time(up to 65535) through this function. If you need to ban an IP address, you can use the AddToBanList member function to ban someone. To kick someone, use the Kick member function with the Player ID of the player to kick as a parameter. Then, in your main loop, call the Receive member function to fill a Packet structure with received data. Check the first entry ([0]) of the data member of the Packet structure against the server-specific values in the PacketEnumerations header file to find out what kind of data was received. When you need to reply to the client, use the Send member function.
Client Side
[edit]Use the Connect member function of the RakClientInterface object you created to connect to the server. You can specify the server address and port number of the remote server through this function. Then, in your main loop, call the Receive member function to fill a Packet structure with received data. Check the first entry ([0]) of the data member of the Packet structure against the server-specific values in the PacketEnumerations header file to find out what kind of data was received. When you need to reply to the server, use the Send member function.