- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# RakPeer Class Reference

The main interface for network communications. More...

`#include <RakPeer.h>`

Inheritance diagram for RakPeer:

List of all members.

## Public Member Functions
| RakPeer ()
| Constructor.
virtual | ~RakPeer ()
| Destructor.
bool | Initialize (unsigned short maxConnections, unsigned short localPort, int _threadSleepTimer, const char *forceHostAddress=0)
| Starts the network threads, opens the listen port. You must call this before calling Connect(). Multiple calls while already active are ignored. To call this function again with different settings, you must first call Disconnect().
void | InitializeSecurity (const char *pubKeyE, const char *pubKeyN, const char *privKeyP, const char *privKeyQ)
void | DisableSecurity (void)
void | SetMaximumIncomingConnections (unsigned short numberAllowed)
unsigned short | GetMaximumIncomingConnections (void) const
void | SetIncomingPassword (const char *passwordData, int passwordDataLength)
void | GetIncomingPassword (char *passwordData, int *passwordDataLength)
bool | Connect (const char *host, unsigned short remotePort, char *passwordData, int passwordDataLength)
| Connect to the specified host (ip or domain name) and server port. Calling Connect and not calling SetMaximumIncomingConnections acts as a dedicated client. Calling both acts as a true peer. This is a non-blocking connection. You know the connection is successful when IsConnected() returns true or Receive() gets a message with the type identifier ID_CONNECTION_ACCEPTED. If the connection is not successful, such as a rejected connection or no response then neither of these things will happen.
void | Disconnect (unsigned int blockDuration, unsigned char orderingChannel=0)
| Stops the network threads and closes all connections.
bool | IsActive (void) const
bool | GetConnectionList (PlayerID *remoteSystems, unsigned short *numberOfSystems) const
bool | Send (const char *data, const int length, PacketPriority priority, PacketReliability reliability, char orderingChannel, PlayerID playerId, bool broadcast)
bool | Send (RakNet::BitStream *bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, PlayerID playerId, bool broadcast)
Packet * | Receive (void)
void | DeallocatePacket (Packet *packet)
unsigned short | GetMaximumNumberOfPeers (void) const
| Return the total number of connections we are allowed.
void | RegisterAsRemoteProcedureCall (char *uniqueID, void(*functionPointer)(RPCParameters *rpcParms))
void | RegisterClassMemberRPC (char *uniqueID, void *functionPointer)
void | UnregisterAsRemoteProcedureCall (char *uniqueID)
bool | RPC (char *uniqueID, const char *data, unsigned int bitLength, PacketPriority priority, PacketReliability reliability, char orderingChannel, PlayerID playerId, bool broadcast, bool shiftTimestamp, NetworkID networkID, RakNet::BitStream *replyFromTarget)
bool | RPC (char *uniqueID, RakNet::BitStream *bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, PlayerID playerId, bool broadcast, bool shiftTimestamp, NetworkID networkID, RakNet::BitStream *replyFromTarget)
void | CloseConnection (const PlayerID target, bool sendDisconnectionNotification, unsigned char orderingChannel=0)
int | GetIndexFromPlayerID (const PlayerID playerId)
PlayerID | GetPlayerIDFromIndex (int index)
void | AddToBanList (const char *IP, RakNetTime milliseconds=0)
void | RemoveFromBanList (const char *IP)
void | ClearBanList (void)
| Allows all previously banned IPs to connect.
bool | IsBanned (const char *IP)
void | Ping (const PlayerID target)
void | Ping (const char *host, unsigned short remotePort, bool onlyReplyOnAcceptingConnections)
int | GetAveragePing (const PlayerID playerId)
int | GetLastPing (const PlayerID playerId) const
int | GetLowestPing (const PlayerID playerId) const
void | SetOccasionalPing (bool doPing)
RakNet::BitStream * | GetRemoteStaticData (const PlayerID playerId)
void | SetRemoteStaticData (const PlayerID playerId, const char *data, const int length)
void | SendStaticData (const PlayerID target)
void | SetOfflinePingResponse (const char *data, const unsigned int length)
PlayerID | GetInternalID (void) const
PlayerID | GetExternalID (const PlayerID target) const
void | SetTimeoutTime (RakNetTime timeMS, const PlayerID target)
bool | SetMTUSize (int size)
int | GetMTUSize (void) const
unsigned | GetNumberOfAddresses (void)
| Returns the number of IP addresses this system has internally. Get the actual addresses from GetLocalIP().
const char * | GetLocalIP (unsigned int index)
| Returns an IP address at index 0 to GetNumberOfAddresses-1.
const char * | PlayerIDToDottedIP (const PlayerID playerId) const
void | IPToPlayerID (const char *host, unsigned short remotePort, PlayerID *playerId)
void | AllowConnectionResponseIPMigration (bool allow)
void | AdvertiseSystem (const char *host, unsigned short remotePort, const char *data, int dataLength)
void | SetSplitMessageProgressInterval (int interval)
void | SetUnreliableTimeout (RakNetTime timeoutMS)
void | SetCompileFrequencyTable (bool doCompile)
bool | GetOutgoingFrequencyTable (unsigned int outputFrequencyTable[256])
bool | GenerateCompressionLayer (unsigned int inputFrequencyTable[256], bool inputLayer)
bool | DeleteCompressionLayer (bool inputLayer)
float | GetCompressionRatio (void) const
float | GetDecompressionRatio (void) const
void | AttachPlugin (PluginInterface *plugin)
void | DetachPlugin (PluginInterface *messageHandler)
void | PushBackPacket (Packet *packet, bool pushAtHead)
void | SetRouterInterface (RouterInterface *routerInterface)
| For internal use only.
void | RemoveRouterInterface (RouterInterface *routerInterface)
| For internal use only.
void | ApplyNetworkSimulator (double maxSendBPS, unsigned short minExtraPing, unsigned short extraPingVariance)
bool | IsNetworkSimulatorActive (void)
RakNetStatisticsStruct *const | GetStatistics (const PlayerID playerId)
RPCMap * | GetRPCMap (const PlayerID playerId)
## Protected Types
enum | { offlinePingResponse_Mutex, NUMBER_OF_RAKPEER_MUTEXES }
## Protected Member Functions
Packet * | ReceiveIgnoreRPC (void)
int | GetIndexFromPlayerID (const PlayerID playerId, bool calledFromNetworkThread)
bool | SendConnectionRequest (const char *host, unsigned short remotePort, char *passwordData, int passwordDataLength)
RemoteSystemStruct * | GetRemoteSystemFromPlayerID (const PlayerID playerID, bool calledFromNetworkThread, bool onlyActive) const
void | ParseConnectionRequestPacket (RakPeer::RemoteSystemStruct *remoteSystem, PlayerID playerId, const char *data, int byteSize)
| Parse out a connection request packet.
void | OnConnectionRequest (RakPeer::RemoteSystemStruct *remoteSystem, unsigned char *AESKey, bool setAESKey)
| When we get a connection request from an ip / port, accept it unless full.
void | NotifyAndFlagForDisconnect (const PlayerID playerId, bool performImmediate, unsigned char orderingChannel)
| Send a reliable disconnect packet to this player and disconnect them when it is delivered.
unsigned short | GetNumberOfRemoteInitiatedConnections (void) const
| Returns how many remote systems initiated a connection to us.
RemoteSystemStruct * | AssignPlayerIDToRemoteSystemList (const PlayerID playerId, RemoteSystemStruct::ConnectMode connectionMode)
| Get a free remote system from the list and assign our playerID to it. Should only be called from the update thread - not the user thread.
void | ShiftIncomingTimestamp (unsigned char *data, PlayerID playerId) const
| An incoming packet has a timestamp, so adjust it to be relative to this system.
RakNetTime | GetBestClockDifferential (const PlayerID playerId) const
| Get the most probably accurate clock differential for a certain player.
bool | HandleRPCPacket (const char *data, int length, PlayerID playerId)
void | HandleRPCReplyPacket (const char *data, int length, PlayerID playerId)
void | GenerateSYNCookieRandomNumber (void)
void | SecuredConnectionResponse (const PlayerID playerId)
void | SecuredConnectionConfirmation (RakPeer::RemoteSystemStruct *remoteSystem, char *data)
bool | RunUpdateCycle (void)
bool | AllowIncomingConnections (void) const
void | SendStaticDataInternal (const PlayerID target, bool performImmediate)
void | PingInternal (const PlayerID target, bool performImmediate)
bool | ValidSendTarget (PlayerID playerId, bool broadcast)
void | CloseConnectionInternal (const PlayerID target, bool sendDisconnectionNotification, bool performImmediate, unsigned char orderingChannel)
void | SendBuffered (const char *data, int numberOfBitsToSend, PacketPriority priority, PacketReliability reliability, char orderingChannel, PlayerID playerId, bool broadcast, RemoteSystemStruct::ConnectMode connectionMode)
bool | SendImmediate (char *data, int numberOfBitsToSend, PacketPriority priority, PacketReliability reliability, char orderingChannel, PlayerID playerId, bool broadcast, bool useCallerDataAllocation, RakNetTimeNS currentTime)
void | ClearBufferedCommands (void)
void | ClearRequestedConnectionList (void)
void | AddPacketToProducer (Packet *p)
## Protected Attributes
volatile bool | endThreads
| Set this to true to terminate the Peer thread execution.
volatile bool | isMainLoopThreadActive
| true if the peer thread is active.
bool | occasionalPing
*unsigned short | maximumNumberOfPeers
| Store the maximum number of peers allowed to connect.
unsigned short | maximumIncomingConnections
| Store the maximum incoming connection allowed.
RakNet::BitStream | localStaticData
| localStaticData necessary because we may not have a RemoteSystemStruct representing ourselves in the list
RakNet::BitStream | offlinePingResponse
PlayerID | myPlayerId
| Local Player ID.
char | incomingPassword [256]
unsigned char | incomingPasswordLength
RemoteSystemStruct * | remoteSystemList
DataStructures::OrderedList< PlayerID, PlayerIDAndIndex, PlayerIDAndIndexComp > | remoteSystemLookup
SimpleMutex | rakPeerMutexes [NUMBER_OF_RAKPEER_MUTEXES]
bool | updateCycleIsRunning
| RunUpdateCycle is not thread safe but we don't need to mutex calls. Just skip calls if it is running already.
unsigned int | bytesSentPerSecond
| Data that both the client and the server needs.
unsigned int | bytesReceivedPerSecond
unsigned int | validationInteger
pthread_t | processPacketsThreadHandle
pthread_t | recvfromThreadHandle
SimpleMutex | incomingQueueMutex
SimpleMutex | banListMutex
DataStructures::List< BanStruct * > | banList
DataStructures::List< PluginInterface * > | messageHandlerList
DataStructures::SingleProducerConsumer< RequestedConnectionStruct > | requestedConnectionList
unsigned int | frequencyTable [256]
| Compression stuff.
HuffmanEncodingTree * | inputTree
HuffmanEncodingTree * | outputTree
unsigned int | rawBytesSent
unsigned int | rawBytesReceived
unsigned int | compressedBytesSent
unsigned int | compressedBytesReceived
DataStructures::SingleProducerConsumer< BufferedCommandStruct > | bufferedCommands
RPCMap | rpcMap
int | MTUSize
bool | trackFrequencyTable
int | threadSleepTimer
SOCKET | connectionSocket
RakNet::BitStream * | replyFromTargetBS
PlayerID | replyFromTargetPlayer
bool | replyFromTargetBroadcast
bool | blockOnRPCReply
RouterInterface * | router
double | _maxSendBPS
unsigned short | _minExtraPing
unsigned short | _extraPingVariance
big::RSACrypt< RSA_BIT_SIZE > | rsacrypt
| Encryption and security.
big::u32 | publicKeyE
RSA_BIT_SIZE | publicKeyN
bool | keysLocallyGenerated
bool | usingSecurity
RakNetTime | randomNumberExpirationTime
unsigned char | newRandomNumber [20]
unsigned char | oldRandomNumber [20]
bool | allowConnectionResponseIPMigration
| True to allow connection accepted packets from anyone. False to only allow these packets from servers we requested a connection to.
int | splitMessageProgressInterval
RakNetTime | unreliableTimeout
DataStructures::SingleProducerConsumer< Packet * > | packetSingleProducerConsumer
DataStructures::Queue< Packet * > | packetPool
## Friends
void | ProcessPortUnreachable (const unsigned int binaryAddress, const unsigned short port, RakPeer *rakPeer)
void | ProcessNetworkPacket (const unsigned int binaryAddress, const unsigned short port, const char *data, const int length, RakPeer *rakPeer)
void * | UpdateNetworkLoop (void *arguments)
## Classes
struct | BanStruct
struct | BufferedCommandStruct
struct | MemoryBlock
| Automatic Variable Synchronization Mechanism automatic variable synchronization takes a primary and secondary identifier The unique primary identifier is the index into the automaticVariableSynchronizationList The unique secondary identifier (UNASSIGNED_NETWORK_ID for none) is in an unsorted list of memory blocks. More...
struct | PingAndClockDifferential
struct | RemoteSystemStruct
struct | RequestedConnectionStruct

## Detailed Description

The main interface for network communications.

The primary interface for RakNet, RakPeer contains all major functions for the library. See the individual functions for what the class can do.

## Member Function Documentation

void RakPeer::AddToBanList | ( | const char * | IP,
|  | RakNetTime | milliseconds = `0`
| ) | `[virtual]`

  | Bans an IP from connecting. Banned IPs persist between connections but are not saved on shutdown nor loaded on startup. param[in] IP Dotted IP address. Can use * as a wildcard, such as 128.0.0.* will ban all IP addresses starting with 128.0.0 Parameters:
  `[in]` | milliseconds | how many ms for a temporary ban. Use 0 for a permanent ban
Implements RakPeerInterface.

void RakPeer::AdvertiseSystem | ( | const char * | host,
|  | unsigned short | remotePort,
|  | const char * | data,
|  | int | dataLength
| ) | `[virtual]`

  | Sends a one byte message ID_ADVERTISE_SYSTEM to the remote unconnected system. This will tell the remote system our external IP outside the LAN along with some user data. Precondition: The sender and recipient must already be started via a successful call to Initialize Parameters:
  `[in]` | host | Either a dotted IP address or a domain name
  `[in]` | remotePort | Which port to connect to on the remote machine.
  `[in]` | data | Optional data to append to the packet.
  `[in]` | dataLength | length of data in bytes. Use 0 if no data.
Implements RakPeerInterface. Reimplemented in RakClient, and RakServer.

void RakPeer::AllowConnectionResponseIPMigration | ( | bool | allow | ) | `[virtual]`

  | Allow or disallow connection responses from any IP. Normally this should be false, but may be necessary when connecting to servers with multiple IP addresses. Parameters:
  `[in]` | allow | - True to allow this behavior, false to not allow. Defaults to false. Value persists between connections
Implements RakPeerInterface. Reimplemented in RakClient.

void RakPeer::ApplyNetworkSimulator | ( | double | maxSendBPS,
|  | unsigned short | minExtraPing,
|  | unsigned short | extraPingVariance
| ) | `[virtual]`

  | Adds simulated ping and packet loss to the outgoing data flow. To simulate bi-directional ping and packet loss, you should call this on both the sender and the recipient, with half the total ping and maxSendBPS value on each. You can exclude network simulator code with the _RELEASE define to decrease code size Parameters:
  `[in]` | maxSendBPS | Maximum bits per second to send. Packetloss grows linearly. 0 to disable.
  `[in]` | minExtraPing | The minimum time to delay sends.
  `[in]` | extraPingVariance | The additional random time to delay sends.
Implements RakPeerInterface. Reimplemented in RakClient, and RakServer.

RakPeer::RemoteSystemStruct * RakPeer::AssignPlayerIDToRemoteSystemList | ( | const PlayerID | playerId,
|  | RemoteSystemStruct::ConnectMode | connectionMode
| ) | `[protected]`

| Get a free remote system from the list and assign our playerID to it. Should only be called from the update thread - not the user thread. Add this player to the lookup tree

void RakPeer::AttachPlugin | ( | PluginInterface * | plugin | ) | `[virtual]`

  | Attatches a Plugin interface to run code automatically on message receipt in the Receive call Note: If plugins have dependencies on each other then the order does matter - for example the router plugin should go first because it might route messages for other plugins Parameters:
  `[in]` | messageHandler | Pointer to a plugin to attach
Implements RakPeerInterface. Reimplemented in RakClient, and RakServer.

void RakPeer::CloseConnection | ( | const PlayerID | target,
|  | bool | sendDisconnectionNotification,
|  | unsigned char | orderingChannel = `0`
| ) | `[virtual]`

  | Close the connection to another host (if we initiated the connection it will disconnect, if they did it will kick them out). Parameters:
  `[in]` | target | Which system to close the connection to.
  `[in]` | sendDisconnectionNotification | True to send ID_DISCONNECTION_NOTIFICATION to the recipient. False to close it silently.
  `[in]` | channel | Which ordering channel to send the disconnection notification on, if any
Implements RakPeerInterface.

bool RakPeer::Connect | ( | const char * | host,
|  | unsigned short | remotePort,
|  | char * | passwordData,
|  | int | passwordDataLength
| ) | `[virtual]`

  | Connect to the specified host (ip or domain name) and server port. Calling Connect and not calling SetMaximumIncomingConnections acts as a dedicated client. Calling both acts as a true peer. This is a non-blocking connection. You know the connection is successful when IsConnected() returns true or Receive() gets a message with the type identifier ID_CONNECTION_ACCEPTED. If the connection is not successful, such as a rejected connection or no response then neither of these things will happen. Precondition: Requires that you first call Initialize Parameters:
  `[in]` | host | Either a dotted IP address or a domain name
  `[in]` | remotePort | Which port to connect to on the remote machine.
  `[in]` | passwordData | A data block that must match the data block on the server passed to SetIncomingPassword. This can be a string or can be a stream of data. Use 0 for no password.
  `[in]` | passwordDataLength | The length in bytes of passwordData
Returns: True on successful initiation. False on incorrect parameters, internal error, or too many existing peers. Returning true does not mean you connected! Implements RakPeerInterface.

void RakPeer::DeallocatePacket | ( | Packet * | packet | ) | `[virtual]`

  | Call this to deallocate a message returned by Receive() when you are done handling it. Parameters:
  `[in]` | packet | The message to deallocate.
Implements RakPeerInterface. Reimplemented in RakClient, and RakServer.

bool RakPeer::DeleteCompressionLayer | ( | bool | inputLayer | ) | `[virtual]`

  | Delete the output or input layer as specified. This is not necessary to call and is only valuable for freeing memory. Precondition: You should only call this when disconnected Parameters:
  `[in]` | inputLayer | True to mean the inputLayer, false to mean the output layer
Returns: false (failure) if connected. Otherwise true (success) Implements RakPeerInterface. Reimplemented in RakClient, and RakServer.

void RakPeer::DetachPlugin | ( | PluginInterface * | messageHandler | ) | `[virtual]`

  | Detaches a Plugin interface to run code automatically on message receipt Parameters:
  `[in]` | messageHandler | Pointer to a plugin to detach
Implements RakPeerInterface. Reimplemented in RakClient, and RakServer.

void RakPeer::DisableSecurity | ( | void |  | ) | `[virtual]`

| Disables all security. Note: Must be called while offline Implements RakPeerInterface. Reimplemented in RakServer.

void RakPeer::Disconnect | ( | unsigned int | blockDuration,
|  | unsigned char | orderingChannel = `0`
| ) | `[virtual]`

  | Stops the network threads and closes all connections. Parameters:
  `[in]` | blockDuration | How long you should wait for all remaining messages to go out, including ID_DISCONNECTION_NOTIFICATION. If 0, it doesn't wait at all.
  `[in]` | orderingChannel | If blockDuration > 0, ID_DISCONNECTION_NOTIFICATION will be sent on this channel If you set it to 0 then the disconnection notification won't be sent
Implements RakPeerInterface. Reimplemented in RakClient, and RakServer.

bool RakPeer::GenerateCompressionLayer | ( | unsigned int | inputFrequencyTable[256],
|  | bool | inputLayer
| ) | `[virtual]`

  | This is an optional function to generate the compression layer based on the input frequency table. If you want to use it you should call this twice - once with inputLayer as true and once as false. The frequency table passed here with inputLayer=true should match the frequency table on the recipient with inputLayer=false. Likewise, the frequency table passed here with inputLayer=false should match the frequency table on the recipient with inputLayer=true. Calling this function when there is an existing layer will overwrite the old layer. Precondition: You should only call this when disconnected Parameters:
  `[in]` | inputFrequencyTable | A frequency table for your data
  `[in]` | inputLayer | Is this the input layer?
Returns: false (failure) if connected. Otherwise true (success) See also: Compression.cpp Implements RakPeerInterface. Reimplemented in RakClient, and RakServer.

int RakPeer::GetAveragePing | ( | const PlayerID | playerId | ) | `[virtual]`

  | Returns the average of all ping times read for the specific system or -1 if none read yet Parameters:
  `[in]` | playerId | Which system we are referring to
Returns: The ping time for this system, or -1 Implements RakPeerInterface. Reimplemented in RakServer.

float RakPeer::GetCompressionRatio | ( | void |  | ) | const`[virtual]`

| Returns the compression ratio. A low compression ratio is good. Compression is for outgoing data Returns: The compression ratio Implements RakPeerInterface. Reimplemented in RakClient, and RakServer.

bool RakPeer::GetConnectionList | ( | PlayerID * | remoteSystems,
|  | unsigned short * | numberOfSystems
| ) | const`[virtual]`

  | Fills the array remoteSystems with the SystemID of all the systems we are connected to Parameters:
  `[out]` | remoteSystems | An array of PlayerID structures to be filled with the PlayerIDs of the systems we are connected to. Pass 0 to remoteSystems to only get the number of systems we are connected to
  `[in,out]` | numberOfSystems | As input, the size of remoteSystems array. As output, the number of elements put into the array
Implements RakPeerInterface.

float RakPeer::GetDecompressionRatio | ( | void |  | ) | const`[virtual]`

| Returns the decompression ratio. A high decompression ratio is good. Decompression is for incoming data Returns: The decompression ratio Implements RakPeerInterface. Reimplemented in RakClient, and RakServer.

PlayerID RakPeer::GetExternalID | ( | const PlayerID | target | ) | const`[virtual]`

  | Return the unique address identifier that represents you on the the network and is based on your externalIP / port (the IP / port the specified player uses to communicate with you) Parameters:
  `[in]` | target | Which remote system you are referring to for your external ID. Usually the same for all systems, unless you have two or more network cards.
Implements RakPeerInterface.

void RakPeer::GetIncomingPassword | ( | char * | passwordData,
|  | int * | passwordDataLength
| ) | `[virtual]`

  | Gets the password passed to SetIncomingPassword Parameters:
  `[out]` | passwordData | Should point to a block large enough to hold the password data you passed to SetIncomingPassword()
  `[in,out]` | passwordDataLength | Maximum size of the array passwordData. Modified to hold the number of bytes actually written
Implements RakPeerInterface.

int RakPeer::GetIndexFromPlayerID | ( | const PlayerID | playerId | ) | `[virtual]`

  | Given a playerID, returns an index from 0 to the maximum number of players allowed - 1. Parameters:
  `[in]` | playerId | The PlayerID we are referring to
Returns: The index of this PlayerID or -1 on system not found. Implements RakPeerInterface. Reimplemented in RakServer.

PlayerID RakPeer::GetInternalID | ( | void |  | ) | const`[virtual]`

| Return the unique address identifier that represents you on the the network and is based on your local IP / port. Returns: the identifier of your system internally, which may not be how other systems see if you if you are behind a NAT or proxy Implements RakPeerInterface. Reimplemented in RakClient, and RakServer.

int RakPeer::GetLastPing | ( | const PlayerID | playerId | ) | const`[virtual]`

  | Returns the last ping time read for the specific system or -1 if none read yet Parameters:
  `[in]` | playerId | Which system we are referring to
Returns: The last ping time for this system, or -1 Implements RakPeerInterface.

int RakPeer::GetLowestPing | ( | const PlayerID | playerId | ) | const`[virtual]`

  | Returns the lowest ping time read or -1 if none read yet Parameters:
  `[in]` | playerId | Which system we are referring to
Returns: The lowest ping time for this system, or -1 Implements RakPeerInterface.

unsigned short RakPeer::GetMaximumIncomingConnections | ( | void |  | ) | const`[virtual]`

| Returns the value passed to SetMaximumIncomingConnections() Returns: the maximum number of incoming connections, which is always <= maxConnections Implements RakPeerInterface.

int RakPeer::GetMTUSize | ( | void |  | ) | const`[virtual]`

| Returns the current MTU size Returns: The current MTU size Implements RakPeerInterface. Reimplemented in RakClient, and RakServer.

bool RakPeer::GetOutgoingFrequencyTable | ( | unsigned int | outputFrequencyTable[256] | ) | `[virtual]`

  | Returns the frequency of outgoing bytes into output frequency table The purpose is to save to file as either a master frequency table from a sample game session for passing to GenerateCompressionLayer() Precondition: You should only call this when disconnected. Requires that you first enable data frequency tracking by calling SetCompileFrequencyTable(true) Parameters:
  `[out]` | outputFrequencyTable | The frequency of each corresponding byte
Returns: False (failure) if connected or if frequency table tracking is not enabled. Otherwise true (success) Implements RakPeerInterface.

PlayerID RakPeer::GetPlayerIDFromIndex | ( | int | index | ) | `[virtual]`

  | This function is only useful for looping through all systems Given an index, will return a PlayerID. Parameters:
  `[in]` | index | Index should range between 0 and the maximum number of players allowed - 1.
Returns: The PlayerID Implements RakPeerInterface. Reimplemented in RakServer.

RakNet::BitStream * RakPeer::GetRemoteStaticData | ( | const PlayerID | playerId | ) | `[virtual]`

  | All systems have a block of data associated with them, for user use. This block of data can be used to easily specify typical system data that you want to know on connection, such as the player's name. Parameters:
  `[in]` | playerId | Which system you are referring to. Pass the value returned by GetInternalID to refer to yourself
Returns: The data passed to SetRemoteStaticData stored as a bitstream Implements RakPeerInterface.

RakPeer::RemoteSystemStruct * RakPeer::GetRemoteSystemFromPlayerID | ( | const PlayerID | playerID,
|  | bool | calledFromNetworkThread,
|  | bool | onlyActive
| ) | const`[protected]`

  | Get the reliability layer associated with a playerID. Parameters:
  `[in]` | playerID | The player identifier
Returns: 0 if none

RakNetStatisticsStruct *const RakPeer::GetStatistics | ( | const PlayerID | playerId | ) | `[virtual]`

  | Returns a structure containing a large set of network statistics for the specified system. You can map this data to a string using the C style StatisticsToString() function Parameters:
  `[in]` | playerId,: | Which connected system to get statistics for
Returns: 0 on can't find the specified system. A pointer to a set of data otherwise. See also: RakNetStatistics.h Implements RakPeerInterface. Reimplemented in RakServer.

bool RakPeer::HandleRPCPacket | ( | const char * | data,
|  | int | length,
|  | PlayerID | playerId
| ) | `[protected]`

  | Handles an RPC packet. This is sending an RPC request Parameters:
  `[in]` | data | A packet returned from Receive with the ID ID_RPC
  `[in]` | length | The size of the packet data
  `[in]` | playerId | The sender of the packet
Returns: true on success, false on a bad packet or an unregistered function

void RakPeer::HandleRPCReplyPacket | ( | const char * | data,
|  | int | length,
|  | PlayerID | playerId
| ) | `[protected]`

  | Handles an RPC reply packet. This is data returned from an RPC call Parameters:
  `[in]` | data | A packet returned from Receive with the ID ID_RPC
  `[in]` | length | The size of the packet data
  `[in]` | playerId | The sender of the packet

bool RakPeer::Initialize | ( | unsigned short | maxConnections,
|  | unsigned short | localPort,
|  | int | _threadSleepTimer,
|  | const char * | forceHostAddress = `0`
| ) | `[virtual]`

  | Starts the network threads, opens the listen port. You must call this before calling Connect(). Multiple calls while already active are ignored. To call this function again with different settings, you must first call Disconnect(). Note: Call SetMaximumIncomingConnections if you want to accept incoming connections Parameters:
  `[in]` | maxConnections | The maximum number of connections between this instance of RakPeer and another instance of RakPeer. Required so the network can preallocate and for thread safety. A pure client would set this to 1. A pure server would set it to the number of allowed clients.- A hybrid would set it to the sum of both types of connections
  `[in]` | localPort | The port to listen for connections on.
  `[in]` | _threadSleepTimer | How many ms to Sleep each internal update cycle (30 to give the game priority, 0 for regular (recommended), -1 to not Sleep() (may be slower))
  `[in]` | forceHostAddress | Can force RakNet to use a particular IP to host on. Pass 0 to automatically pick an IP
Returns: False on failure (can't create socket or thread), true on success. Implements RakPeerInterface.

void RakPeer::InitializeSecurity | ( | const char * | pubKeyE,
|  | const char * | pubKeyN,
|  | const char * | privKeyP,
|  | const char * | privKeyQ
| ) | `[virtual]`

  | Secures connections though a combination of SHA1, AES128, SYN Cookies, and RSA to prevent connection spoofing, replay attacks, data eavesdropping, packet tampering, and MitM attacks. There is a significant amount of processing and a slight amount of bandwidth overhead for this feature. If you accept connections, you must call this or else secure connections will not be enabled for incoming connections. If you are connecting to another system, you can call this with values for the (e and p,q) public keys before connecting to prevent MitM Precondition: Must be called before Initialize Parameters:
  `[in]` | pubKeyE | A pointer to the public keys from the RSACrypt class.
  `[in]` | pubKeyN | A pointer to the public keys from the RSACrypt class.
  `[in]` | privKeyP | Public key generated from the RSACrypt class.
  `[in]` | privKeyQ | Public key generated from the RSACrypt class. If the private keys are 0, then a new key will be generated when this function is called
See also: the Encryption sample Implements RakPeerInterface.

void RakPeer::IPToPlayerID | ( | const char * | host,
|  | unsigned short | remotePort,
|  | PlayerID * | playerId
| ) | `[virtual]`

  | Converts a dotted IP to a playerId Parameters:
  `[in]` | host | Either a dotted IP address or a domain name
  `[in]` | remotePort | Which port to connect to on the remote machine.
  `[out]` | playerId | The result of this operation
Implements RakPeerInterface.

bool RakPeer::IsActive | ( | void |  | ) | const`[inline, virtual]`

| Returns if the network thread is running Returns: true if the network thread is running, false otherwise Implements RakPeerInterface. Reimplemented in RakServer.

bool RakPeer::IsBanned | ( | const char * | IP | ) | `[virtual]`

  | Returns true or false indicating if a particular IP is banned. Parameters:
  `[in]` | IP | - Dotted IP address.
Returns: true if IP matches any IPs in the ban list, accounting for any wildcards. False otherwise. Implements RakPeerInterface. Reimplemented in RakServer.

bool RakPeer::IsNetworkSimulatorActive | ( | void |  | ) | `[virtual]`

| Returns if you previously called ApplyNetworkSimulator Returns: If you previously called ApplyNetworkSimulator Implements RakPeerInterface. Reimplemented in RakClient, and RakServer.

void RakPeer::Ping | ( | const char * | host,
|  | unsigned short | remotePort,
|  | bool | onlyReplyOnAcceptingConnections
| ) | `[virtual]`

  | Send a ping to the specified unconnected system. The remote system, if it is Initialized, will respond with ID_PONG. The final ping time will be encoded in the following sizeof(RakNetTime) bytes. (Default is 4 bytes - See __GET_TIME_64BIT in NetworkTypes.h Parameters:
  `[in]` | host | Either a dotted IP address or a domain name. Can be 255.255.255.255 for LAN broadcast.
  `[in]` | remotePort | Which port to connect to on the remote machine.
  `[in]` | onlyReplyOnAcceptingConnections | Only request a reply if the remote system is accepting connections
Implements RakPeerInterface.

void RakPeer::Ping | ( | const PlayerID | target | ) | `[virtual]`

  | Send a ping to the specified connected system. Precondition: The sender and recipient must already be started via a successful call to Initialize() Parameters:
  `[in]` | target | Which system to ping
Implements RakPeerInterface.

const char * RakPeer::PlayerIDToDottedIP | ( | const PlayerID | playerId | ) | const`[virtual]`

  | TODO - depreciate this Returns the dotted IP address for the specified playerId Parameters:
  `[in]` | playerId | Any player ID other than UNASSIGNED_PLAYER_ID, even if that player is not currently connected
Implements RakPeerInterface. Reimplemented in RakClient.

void RakPeer::PushBackPacket | ( | Packet * | packet,
|  | bool | pushAtHead
| ) | `[virtual]`

  | Put a message back at the end of the receive queue in case you don't want to deal with it immediately Parameters:
  `[in]` | packet | The packet you want to push back.
  `[in]` | pushAtHead | True to push the packet so that the next receive call returns it. False to push it at the end of the queue (obviously pushing it at the end makes the packets out of order)
Implements RakPeerInterface. Reimplemented in RakClient, and RakServer.

Packet * RakPeer::Receive | ( | void |  | ) | `[virtual]`

| Gets a message from the incoming message queue. Use DeallocatePacket() to deallocate the message after you are done with it. User-thread functions, such as RPC calls and the plugin function PluginInterface::Update occur here. Returns: 0 if no packets are waiting to be handled, otherwise a pointer to a packet. sa NetworkTypes.h contains struct Packet Implements RakPeerInterface. Reimplemented in RakClient, and RakServer.

void RakPeer::RemoveFromBanList | ( | const char * | IP | ) | `[virtual]`

| Allows a previously banned IP to connect. param[in] Dotted IP address. Can use * as a wildcard, such as 128.0.0.* will banAll IP addresses starting with 128.0.0 Implements RakPeerInterface. Reimplemented in RakServer.

bool RakPeer::Send | ( | RakNet::BitStream * | bitStream,
|  | PacketPriority | priority,
|  | PacketReliability | reliability,
|  | char | orderingChannel,
|  | PlayerID | playerId,
|  | bool | broadcast
| ) | `[virtual]`

  | Sends a block of data to the specified system that you are connected to. Same as the above version, but takes a BitStream as input. Parameters:
  `[in]` | bitStream | The bitstream to send
  `[in]` | priority | What priority level to send on. See PacketPriority.h
  `[in]` | reliability | How reliability to send this data. See PacketPriority.h
  `[in]` | orderingChannel | When using ordered or sequenced messages, what channel to order these on. Messages are only ordered relative to other messages on the same stream
  `[in]` | playerId | Who to send this packet to, or in the case of broadcasting who not to send it to. Use UNASSIGNED_PLAYER_ID to specify none
  `[in]` | broadcast | True to send this packet to all connected systems. If true, then playerId specifies who not to send the packet to.
Returns: False if we are not connected to the specified recipient. True otherwise Implements RakPeerInterface. Reimplemented in RakServer.

bool RakPeer::Send | ( | const char * | data,
|  | const int | length,
|  | PacketPriority | priority,
|  | PacketReliability | reliability,
|  | char | orderingChannel,
|  | PlayerID | playerId,
|  | bool | broadcast
| ) | `[virtual]`

  | Sends a block of data to the specified system that you are connected to. This function only works while the connected Parameters:
  `[in]` | data | The block of data to send
  `[in]` | length | The size in bytes of the data to send
  `[in]` | priority | What priority level to send on. See PacketPriority.h
  `[in]` | reliability | How reliability to send this data. See PacketPriority.h
  `[in]` | orderingChannel | When using ordered or sequenced messages, what channel to order these on. Messages are only ordered relative to other messages on the same stream
  `[in]` | playerId | Who to send this packet to, or in the case of broadcasting who not to send it to. Use UNASSIGNED_PLAYER_ID to specify none
  `[in]` | broadcast | True to send this packet to all connected systems. If true, then playerId specifies who not to send the packet to.
Returns: False if we are not connected to the specified recipient. True otherwise Implements RakPeerInterface. Reimplemented in RakServer.

void RakPeer::SendStaticData | ( | const PlayerID | target | ) | `[virtual]`

  | Sends your static data to the specified system. This is automatically done on connection. You should call this when you change your static data.To send the static data of another system (such as relaying their data) you should do this normally with Send) Parameters:
  `[in]` | target | Who to send your static data to. Specify UNASSIGNED_PLAYER_ID to broadcast to all
Implements RakPeerInterface.

void RakPeer::SetCompileFrequencyTable | ( | bool | doCompile | ) | `[virtual]`

  | Enables or disables frequency table tracking. This is required to get a frequency table, which is used in GenerateCompressionLayer() This value persists between connect calls and defaults to false (no frequency tracking) Precondition: You can call this at any time - however you SHOULD only call it when disconnected. Otherwise you will only trackpart of the values sent over the network. Parameters:
  `[in]` | doCompile | True to enable tracking
Implements RakPeerInterface.

void RakPeer::SetIncomingPassword | ( | const char * | passwordData,
|  | int | passwordDataLength
| ) | `[virtual]`

  | Sets the password incoming connections must match in the call to Connect (defaults to none). Pass 0 to passwordData to specify no password This is a way to set a low level password for all incoming connections. To selectively reject connections, implement your own scheme using CloseConnection() to remove unwanted connections Parameters:
  `[in]` | passwordData | A data block that incoming connections must match. This can be just a password, or can be a stream of data. Specify 0 for no password data
  `[in]` | passwordDataLength | The length in bytes of passwordData
Implements RakPeerInterface.

void RakPeer::SetMaximumIncomingConnections | ( | unsigned short | numberAllowed | ) | `[virtual]`

  | Sets how many incoming connections are allowed. If this is less than the number of players currently connected, no more players will be allowed to connect. If this is greater than the maximum number of peers allowed, it will be reduced to the maximum number of peers allowed. Defaults to 0. Parameters:
  `[in]` | numberAllowed | Maximum number of incoming connections allowed.
Implements RakPeerInterface.

bool RakPeer::SetMTUSize | ( | int | size | ) | `[virtual]`

| Set the MTU per datagram. It's important to set this correctly - otherwise packets will be needlessly split, decreasing performance and throughput. Maximum allowed size is MAXIMUM_MTU_SIZE. Too high of a value will cause packets not to arrive at worst and be fragmented at best. Too low of a value will split packets unnecessarily. Recommended size is 1500 sa MTUSize.h Precondition: Can only be called when not connected. Returns: false on failure (we are connected), else true Implements RakPeerInterface. Reimplemented in RakClient, and RakServer.

void RakPeer::SetOccasionalPing | ( | bool | doPing | ) | `[virtual]`

  | Ping the remote systems every so often, or not. This is off by default. Can be called anytime. Parameters:
  `[in]` | doPing | True to start occasional pings. False to stop them.
Implements RakPeerInterface.

void RakPeer::SetOfflinePingResponse | ( | const char * | data,
|  | const unsigned int | length
| ) | `[virtual]`

  | Sets the data to send along with a LAN server discovery or offline ping reply. length should be under 400 bytes, as a security measure against flood attacks Parameters:
  `[in]` | data | a block of data to store, or 0 for none
  `[in]` | length | The length of data in bytes, or 0 for none
See also: Ping.cpp Implements RakPeerInterface. Reimplemented in RakServer.

void RakPeer::SetRemoteStaticData | ( | const PlayerID | playerId,
|  | const char * | data,
|  | const int | length
| ) | `[virtual]`

  | All systems have a block of data associated with them, for user use. This block of data can be used to easily specify typical system data that you want to know on connection, such as the player's name. Parameters:
  `[in]` | playerId | Whose static data to change. Use your own playerId to change your own static data
  `[in]` | data | a block of data to store
  `[in]` | length | The length of data in bytes
Implements RakPeerInterface.

void RakPeer::SetSplitMessageProgressInterval | ( | int | interval | ) | `[virtual]`

  | Controls how often to return ID_DOWNLOAD_PROGRESS for large message downloads. ID_DOWNLOAD_PROGRESS is returned to indicate a new partial message chunk, roughly the MTU size, has arrived As it can be slow or cumbersome to get this notification for every chunk, you can set the interval at which it is returned. Defaults to 0 (never return this notification) Parameters:
  `[in]` | interval | How many messages to use as an interval
Implements RakPeerInterface.

void RakPeer::SetTimeoutTime | ( | RakNetTime | timeMS,
|  | const PlayerID | target
| ) | `[virtual]`

  | Parameters:
  `[in]` | timeMS | Time, in MS
  `[in]` | target | Which system to do this for
Implements RakPeerInterface. Reimplemented in RakServer.

void RakPeer::SetUnreliableTimeout | ( | RakNetTime | timeoutMS | ) | `[virtual]`

  | Set how long to wait before giving up on sending an unreliable message Useful if the network is clogged up. Set to 0 or less to never timeout. Defaults to 0. Parameters:
  `[in]` | timeoutMS | How many ms to wait before simply not sending an unreliable message.
Implements RakPeerInterface.

## Member Data Documentation

* unsigned short RakPeer::maximumNumberOfPeers`[protected]`

| Store the maximum number of peers allowed to connect. Do we occasionally ping the other systems?

RemoteSystemStruct* RakPeer::remoteSystemList`[protected]`

| This is an array of pointers to RemoteSystemStruct This allows us to preallocate the list when starting, so we don't have to allocate or delete at runtime. Another benefit is that is lets us add and remove active players simply by setting playerId and moving elements in the list by copying pointers variables without affecting running threads, even if they are in the reliability layer

The documentation for this class was generated from the following files:

- C:/RakNet 2.518/Include/RakPeer.h
- C:/RakNet 2.518/Source/RakPeer.cpp