System Overview

Internals Overview RakNet has three major topological systems: The server, client, and peer. The server and client are specialized instances of the peer with extra features that are handled in the Recieve function - The ID_REMOTE_* packet set, relayed ping, relayed static data information and other minor things. When a peer is created, it creates an update thread which runs in either a poll or update state. The poll state checks to see if Receive is being called on a regular basis. If so, the thread sleeps until the next poll time. Otherwise, it enters the update state in which case the thread handles normal traffic communications. If IO completion ports are used, two additional threads are created for the IO completion port thread pool. This pool is shared among all instances of RakNet. When you or the system sends a message it is parsed, compressed if compression is used, and send to the reliability layer. The reliability layer will get or create one or more InternalPacket objects from the pool of these objects, depending on whether the message needs to be split to fit under the MTU. The InternalPacket class contains all the various parameters describing the message. This object is then saved in one of several lists, depending on the priority level used. The update thread's main responsibility is to call the Update function of the reliability layer. The update function checks to see if it is time to send a frame. If so, a frame is created which contains user messages, packet acks, and reliable resends. The frame is encrypted, statistics are updated, and a packet is sent. This loops until the send window is full or there is no more data. When a message arrives it is decrypted, validated, and parsed into individual messages. The window size is updated. If a message was split and all pieces have arrived the original message is reassembled. If the message is an ack, duplicate, sequenced, or ordered it is handled appropriately. Messages that are intended for the user at this time will be sent to RakPeer, which will decompress it if compression is activated. Certain system messages will be handled immediately such as lost connection notifications. Certain system messages, and messages that originated from the user, will be put into a Packet struct which is allocated from a pool, and will be saved in a mutexed queue. When Receive is called the queue is popped and the popped packet is parsed. Certain kinds of packets are not returned to the user, such as RPC packets which will instead call a function. If a packet is returned, sometimes the packet is intended for another user-level system such as distributed network objects, RakVoice, or the master server. These are handled in the Multiplayer class, if you use it. Major classes These are the main classes you will be dealing with. The filename of each class is the same as the name of each class. The header for each class contains much more detailed information and a full list of functions, so you should refer there for additional information. RakPeer The core of RakNet is RakPeer and it is the lowest level you would normally work at. It is a peer to peer networking system encompassing enhanced reliable UDP with flow control and various ordering and prioritizing schemes. It can compose any topology and has msot of the major funtionality of RakNet. RakServer RakServer is a layer over RakPeer where it is assumed there are only incoming connections and no outgoing connections. It provides the user with additional functionality such as the ability to override static data of remote systems and the synchronized random number seed. RakClient RakClient is a layer over RakPeer designed to work in conjunction with RakServer. It is assumed there is only one outgoing connection and no incoming connections. It provides the user with additional information such as remote clients connecting and disconnecting plus the functionality the server provides such as the synchronized random number seed. RakVoice RakVoice is a layer over RakPeer that uses the external Speex library to encode and decode voice data. The sample uses the external PortAudio library to play sound. BitStream BitStream is a helper class used throughout RakNet. It allows encoding of data into a stream at, if desired, the bit level. It also handles data compression and decompression so you can encode data more efficiently. Many of RakNet's functions use bitstreams, especially those with variable parameter lengths such as remote procedure calls. Multiplayer.h Multiplayer is a helper class that checks for packets, parses the packet based on the identifier, calls a handler function, and then deallocates the packet. It is nothing more than a framework to get started from. However, it does call the distributed object manager for distributed object packets so saves you the trouble of doing that. DistributedNetworkObject The DistributedNetworkObject is a class you can derive from that will give your classes the ability to automatically propigate themselves over the network and to synchronize member variables. It derives from NetworkObject, which provides a unique identifier for all your instanced classes so you can refer to them over the network. It assumes you are working in a client / server enviroment and requires registration of your client and / or server with the DistributedNetworkObjectManager Singleton. Major features All of these features are supported by the peer, server, and client. These are implemented through one or more functions in the class interface. Please refer to the linked documentation pages and the header files for full details. IO Completion ports [Currently Disabled] Under Windows, there is a mechanism called IO completion ports where the network card can write directly to and read directly from memory. It awakens a handler thread when there is network data waiting. These threads are in a common pool such that multiple instances of the client and/or server share the pool. It supposedly improves performance when handling thousands of clients. Remote Procedure Calls Remote procedure calls allow you to call functions on other systems that follow a particular prototype. RPC functions take a bitstream and so can handle any length or type of data. It is much easier to use RPC than to create custom packet identifiers. Timestamping Timestamps encoded in packets allow you to accurately determine when an event on another computer occured, even though their system clocks are different. Global Data Compression RakNet can analyze the typical traffic that goes in and out of your client and server and apply compression to it. This usually results in about 30% less bandwidth usage but requires additional CPU usage. Unlike most other features, this requires some work on the part of the user to setup. Automatic Memory Synchronization This is an older features that has been made obsolete by distributed objects. What it does is scans a specified block of memory for changes everytime you call Receive. If any memory has changed, it sends a packet to the remote systems to synchronize it. Next page: Detailed Implementation

See Also

Index Introduction Detailed Implementation Tutorial Compiler Setup