#include <XPSession.h>
Public Types | |
| enum | Error { kXPSession_EOK = 0, kXPSession_EERROR = -1, kXPSession_ETRANSPORT_CLOSED = -2, kXPSession_ETRANSPORT_ERROR = -3 } |
Public Member Functions | |
| XPSession () | |
| virtual | ~XPSession () |
| virtual void | Create (const std::string name)=0 |
| virtual void | Create (const std::string name, const std::string protocols)=0 |
| virtual std::string | ExportURL (const bool shortAddress=true)=0 |
| virtual void | Join (const std::string url)=0 |
| virtual void | Find (void)=0 |
| virtual void | Find (const std::string protocols)=0 |
| virtual std::string | EnumerateFound (void)=0 |
| virtual int | GetGameChannel (void)=0 |
| virtual void | SetGameChannel (const int channel=TransportAnyGameChannel)=0 |
| virtual int | GetSessionID (void)=0 |
| virtual bool | IsStable (void)=0 |
| virtual Error | GetStatus (void)=0 |
| virtual Error | GetSessionErrorReason (void)=0 |
| virtual void | DataSendToSession (const int sessionid, const char *data, const int length, const bool reliable=true, const bool certain=false, const unsigned int band=0)=0 |
| virtual void | DataSendToSessionUnreliable (const int sessionid, const char *data, const int length)=0 |
| virtual void | DataSendToSessionReliable (const int sessionid, const char *data, const int length, const unsigned int band=0)=0 |
| virtual void | DataSendToSessionCertain (const int sessionid, const char *data, const int length)=0 |
| virtual bool | DataReceivePeek (int *const fromsessionid, int *const length, unsigned char *const type=0)=0 |
| virtual bool | DataReceive (int *const fromsessionid, char *const data, int *const length, unsigned char *const type=0)=0 |
| virtual bool | IsMaster (void)=0 |
| virtual int | GetJoiner (void)=0 |
| virtual int | GetLeaver (void)=0 |
| virtual float | GetTime (void)=0 |
| virtual float | GetLocalTime (void)=0 |
| virtual float | GetNetworkSendRate (void)=0 |
| virtual float | GetNetworkReceiveRate (void)=0 |
| virtual int | GetNetworkPacketsLost (void)=0 |
| virtual void | Poll (void)=0 |
| virtual void | SetPollLayerBelow (bool enable=true)=0 |
| virtual bool | GetPollLayerBelow (void)=0 |
| virtual void | SetManualPoll (void)=0 |
| virtual void | SetAutomaticPoll (void)=0 |
| virtual void | SetManualPollXPURL (void)=0 |
| virtual void | SetAutomaticPollXPURL (void)=0 |
| virtual void | SetCanSpider (const bool canSpider=true)=0 |
| virtual bool | GetCanSpider (void)=0 |
| virtual void | SetCanBecomeMaster (const bool canBeMaster=true)=0 |
| virtual bool | GetCanBecomeMaster (void)=0 |
| virtual float | GetLatencyToMasterSession (void)=0 |
| virtual float | GetLatencyToSessionID (const int sessionID)=0 |
| virtual void | SetLatencyRecalculationDelay (const float seconds=1.0f)=0 |
| virtual void | SetEncryption (const bool enable=false)=0 |
| virtual bool | GetEncryption (void)=0 |
| virtual void | Disconnect (const int sessionID=kXPSessionUnknownID)=0 |
| virtual bool | GetPreConnectStatus (void)=0 |
| virtual void | SetPreConnect (const bool enable=false)=0 |
| virtual bool | GetPreConnect (void)=0 |
| virtual void | PreConnectHasFinished (void)=0 |
| virtual void | SetAutomaticPacketCompression (const bool enable=false)=0 |
| virtual bool | GetAutomaticPacketCompression (void)=0 |
| virtual void | GetCompressionStatistics (int *const before=0, int *const after=0, const bool reset=false)=0 |
| virtual void | GetMergedStatistics (int *const sent=0, int *const received=0, const bool reset=false)=0 |
| virtual int | GetMasterSessionID (void)=0 |
| virtual std::string | GetURLFromSessionID (const int sessionID)=0 |
| virtual void | SetClientOnly (const bool isClient=false)=0 |
| virtual bool | GetClientOnly (void)=0 |
| virtual bool | GetBandwidthFromSessionID (const int sessionID, Transport::Bandwidth *const bandwidth, int *const output, int *const input)=0 |
| virtual void | SetAllowConnections (const bool allow=true)=0 |
| virtual bool | GetAllowConnections (void)=0 |
| virtual void | SetNodeBuffers (const bool enable=false)=0 |
| virtual bool | GetNodeBuffers (void)=0 |
Static Public Member Functions | |
| static XPSession * | Allocate (void) |
| virtual ~XPSession | ( | ) | [inline, virtual] |
The dtor for an XPSession This cleans up everything for this class
| static XPSession* Allocate | ( | void | ) | [static] |
Allocates a new session to be used
| virtual void Create | ( | const std::string | name | ) | [pure virtual] |
Creates a new session using the default available protocols.
When this XPSession instance is disconnected from a session this XPSession instance should be deleted and a new instance allocated before attempting to create or join a session.
| name | The name to give to this session. The maximum length of this string is 128 characters. |
| virtual void Create | ( | const std::string | name, | |
| const std::string | protocols | |||
| ) | [pure virtual] |
Creates a new session using the supplied protocols
When this XPSession instance is disconnected from a session this XPSession instance should be deleted and a new instance allocated before attempting to create or join a session.
| name | The name to give to this session | |
| protocols | The list of protocols to use separated by commas. e.g. "UDP@,STREAMTCPIP@" |
| virtual std::string ExportURL | ( | const bool | shortAddress = true |
) | [pure virtual] |
Exports a URL that can be used to connect to this session in future. The format of the URL is as follows:
"SESSION://" the URL header.
Any number of exported Transport URLs separated with a '/'. Transport URLs are in the format "Transport type"@"address"
The standard XPSession brace block which contains: {SESSIONNAME=<session name>="">}
Any number of user defined brace blocks.
An example is as follows: SESSION://UDP.0.0.1:4000/{SESSIONNAME=Game}
| shortAddress | If this is true then only the short address for this session is exported. The short address only contains the address of the master listen transports, the long address also contains the listen addresses for the spider connections if they are available. By default the short address is exported. |
| virtual void Join | ( | const std::string | url | ) | [pure virtual] |
| virtual void Find | ( | void | ) | [pure virtual] |
Tries to find sessions using the default protocols
| virtual void Find | ( | const std::string | protocols | ) | [pure virtual] |
Tries to find sessions using the listed protocols
| protocols | The list of protocols to use separated by commas. e.g. "UDP@,STREAMTCPIP@" |
| virtual std::string EnumerateFound | ( | void | ) | [pure virtual] |
Enumerates any found sessions
| virtual int GetGameChannel | ( | void | ) | [pure virtual] |
Gets the current channel number for this session
| virtual void SetGameChannel | ( | const int | channel = TransportAnyGameChannel |
) | [pure virtual] |
Sets the current channel number for this session. If no channel number is passed then TransportAnyGameChannel is used.
| channel | The channel number to use. |
| virtual int GetSessionID | ( | void | ) | [pure virtual] |
Gets the session unique ID
| virtual bool IsStable | ( | void | ) | [pure virtual] |
This allows the user o check if the session is really stable.
| virtual Error GetStatus | ( | void | ) | [pure virtual] |
Gets the session status. A session error happens when the master session disconnects and a new master cannot be found.
| virtual Error GetSessionErrorReason | ( | void | ) | [pure virtual] |
This can be used to read extended information when XPSession encounters a session error.
| virtual void DataSendToSession | ( | const int | sessionid, | |
| const char * | data, | |||
| const int | length, | |||
| const bool | reliable = true, |
|||
| const bool | certain = false, |
|||
| const unsigned int | band = 0 | |||
| ) | [pure virtual] |
Sends data from this session to any other session via its ID or to all sessions by using XPSessionBroadcastID. If the node is in a pre-connect state and wants to send data to the master session then use kXPSessionUnknownID as the session ID to send to.
Data packets larger than 512 bytes can be sent and received correctly however these large packets may cause a performance hit as the large chunk of data is sent. A sessionID will not receive any data sent to itself either by using its own sessionID or from a broadcast.
The other functions DataSendToSessionXXX use this function
| sessionid | the session id to send to or XPSessionBroadcastID. | |
| data | the pointer to the data to send | |
| length | the length of the data to send. | |
| reliable | a flag to make this packet reliable, the default is true | |
| certain | a flag to make this packet certain, the default is false | |
| band | The band to use for the underlying Transport when sending with the Reliable method. |
| virtual void DataSendToSessionUnreliable | ( | const int | sessionid, | |
| const char * | data, | |||
| const int | length | |||
| ) | [pure virtual] |
Sends data using the 'Unreliable' packet type from this session to any other session via it's ID or to all sessions by using XPSessionBroadcastID
| sessionid | the session id to send to or XPSessionBroadcastID | |
| data | the pointer to the data to send. | |
| length | the length of the data to send. |
| virtual void DataSendToSessionReliable | ( | const int | sessionid, | |
| const char * | data, | |||
| const int | length, | |||
| const unsigned int | band = 0 | |||
| ) | [pure virtual] |
Sends data using the 'Reliable' packet type from this session to any other session via it's ID or to all sessions by using XPSessionBroadcastID
| sessionid | the session id to send to or XPSessionBroadcastID | |
| data | the pointer to the data to send. | |
| length | the length of the data to send. | |
| band | The band to use for the underlying Transport when sending with the Reliable method. |
| virtual void DataSendToSessionCertain | ( | const int | sessionid, | |
| const char * | data, | |||
| const int | length | |||
| ) | [pure virtual] |
Sends data using the 'Certain' packet type from this session to any other session via it's ID or to all sessions by using XPSessionBroadcastID
| sessionid | the session id to send to or XPSessionBroadcastID | |
| data | the pointer to the data to send | |
| length | the length of the data to send. |
| virtual bool DataReceivePeek | ( | int *const | fromsessionid, | |
| int *const | length, | |||
| unsigned char *const | type = 0 | |||
| ) | [pure virtual] |
This allows the parameters of the next pending received data to be read. The data is left waiting to be read by DataReceive.
| fromsessionid | the session id that sent this data. | |
| length | the length of the data received. | |
| type | a pointer that can receive the packet type. This with be kXPSessionPacketType_Unreliable, kXPSessionPacketType_Certain or kXPSessionPacketType_Reliable. This parameter can be null in which case the type is not filled in. The default value for this pointer is null. |
| virtual bool DataReceive | ( | int *const | fromsessionid, | |
| char *const | data, | |||
| int *const | length, | |||
| unsigned char *const | type = 0 | |||
| ) | [pure virtual] |
Receives data and responds with what session sent this data.
| fromsessionid | the session id that sent this data. | |
| data | the buffer for the data. | |
| length | the length of the data received. | |
| type | a pointer that can receive the packet type. This with be kXPSessionPacketType_Unreliable, kXPSessionPacketType_Certain or kXPSessionPacketType_Reliable. This parameter can be null in which case the type is not filled in. The default value for this pointer is null. |
| virtual bool IsMaster | ( | void | ) | [pure virtual] |
Tests to see if this session is a master session
| virtual int GetJoiner | ( | void | ) | [pure virtual] |
Gets the session id that recently joined the network session
| virtual int GetLeaver | ( | void | ) | [pure virtual] |
Gets the session id that left the network session
| virtual float GetTime | ( | void | ) | [pure virtual] |
Gets the current system time of this ReplicaNet session synchronised with the time on the session master.
| virtual float GetLocalTime | ( | void | ) | [pure virtual] |
Gets the current local time. This time is local to the session and is not synchronised to the session master clock.
| virtual float GetNetworkSendRate | ( | void | ) | [pure virtual] |
Gets the current network send transfer rate in bytes per second
| virtual float GetNetworkReceiveRate | ( | void | ) | [pure virtual] |
Gets the current network receive transfer rate in bytes per second
| virtual int GetNetworkPacketsLost | ( | void | ) | [pure virtual] |
Gets the number of packets that are lost and lost and resent
| virtual void Poll | ( | void | ) | [pure virtual] |
This polls XPSession. Normally an application will yield enough time during threads for XPSession to function. Sometimes an application that uses a lot of 3D graphics can lock out other threads for quite some time. In these cases you may call XPSession::Poll() to yield some time to XPSession to perform housekeeping.
Single threaded considerations:
When using the single threaded libraries this method should be called regularly. Unless ReplicaNet::Poll() is called in which case this Poll() method is already called.
| virtual void SetPollLayerBelow | ( | bool | enable = true |
) | [pure virtual] |
This allows the user to determine if during a Poll() the layer below also gets called. For single threaded applications this function has no effect as the layer below always has the Poll() called. The default is true.
The layer below in this case is XPURL.
| enable | Enable or disable layer below polling. |
| virtual bool GetPollLayerBelow | ( | void | ) | [pure virtual] |
Allows the state of SetPollLayerBelow() to be read. If the library is always single threading then this function will always return true.
| virtual void SetManualPoll | ( | void | ) | [pure virtual] |
Sets the manual Poll() method for this class only.
For multi-threaded libraries this turns off the automatic polling method.
This allows an application to time exactly when polls are done.
The application must call Poll() on a regular basis. A good place is just before or after the frame update is done.
| virtual void SetAutomaticPoll | ( | void | ) | [pure virtual] |
Sets the automatic Poll() method In multi-threading libraries this restarts the automatic polling thread so that an application does not need the call Poll()
In single-threading libraries this method has no effect and does not start a thread.
The default multi-threading library behaviour is to enable multi-threading automatic polls,
The default single-threading library behaviour is to use manual polls,
| virtual void SetManualPollXPURL | ( | void | ) | [pure virtual] |
This allows the poll method to be set for the XPURL layer that is used by this session.
| virtual void SetAutomaticPollXPURL | ( | void | ) | [pure virtual] |
This allows the poll method to be set for the XPURL layer that is used by this session.
| virtual void SetCanSpider | ( | const bool | canSpider = true |
) | [pure virtual] |
This allows the user to enable or disable spidering of network connections
| canSpider | Pass in true to enable spidering or false to disable spidering The default is true |
| virtual bool GetCanSpider | ( | void | ) | [pure virtual] |
This allows the spidering state to be read /return the status of the spidering state
| virtual void SetCanBecomeMaster | ( | const bool | canBeMaster = true |
) | [pure virtual] |
This allows the session to set if it can become a master due to a fault being found from another session
| canBeMaster | Pass in true to enable this session to become a master if needed. The default is true Currently a session can only become a master if it is enabled for spidering however. |
| virtual bool GetCanBecomeMaster | ( | void | ) | [pure virtual] |
Allows the state to be read
| virtual float GetLatencyToMasterSession | ( | void | ) | [pure virtual] |
This allows the latency to the master session to be read. This is the time taken for a packet to reach the master session. This is half round trip ping time.
| virtual float GetLatencyToSessionID | ( | const int | sessionID | ) | [pure virtual] |
This allows the latency to the sessionID to be read. This is the time taken for a packet to reach the sessionID. This is half round trip ping time.
| virtual void SetLatencyRecalculationDelay | ( | const float | seconds = 1.0f |
) | [pure virtual] |
This allows the latency recalculation delay to be set. The default value is 1 second meaning there is a ping packet sent every second.
| seconds | The number of seconds before latency is recalculated. |
| virtual void SetEncryption | ( | const bool | enable = false |
) | [pure virtual] |
Enables or disables encryption for this session
| enable | set this to be true to enable encryption for packets sent from this session. The default is false |
| virtual bool GetEncryption | ( | void | ) | [pure virtual] |
Gets the status of the encryption flag for this session
| virtual void Disconnect | ( | const int | sessionID = kXPSessionUnknownID |
) | [pure virtual] |
This forces a disconnect from the supplied sessionID or if the sessionID is not supplied then all session nodes are disconnected. The disconnect is immediate and initiates the fault tolerant mechanism for XPSession and ReplicaNet on other connected session nodes. This means if the session was a master session node then the other session nodes will try to find a new master if this mechanism is enabled. In the case of a ReplicaNet session node having objects, these objects will attempt to use the fault recovery and migration to other nodes if it is enabled.
| sessionID | The sessionID to disconnect from. The default is to disconnect from all sessionIDs. |
| virtual bool GetPreConnectStatus | ( | void | ) | [pure virtual] |
Allows the status of the pre-connect mechanism to be tested.
| virtual void SetPreConnect | ( | const bool | enable = false |
) | [pure virtual] |
Enables or disables the pre-connect mechanism for session nodes that are joining a session. When this mechanism is enabled the joining session node will be able to exchange packets with the master session node before the node properly joins the session. The function PreConnectHasFinished() can be called to signal that the node wishes to complete a connect to the session. This function should only be used before a session node is used to join the session. The function IsStable() will not return true until the pre-connect is finished.
The intended for this mechanism is as follows:
1) SetPreConnect(true) and attempts to join a session. All calls to GetSessionID() will return kXPSessionUnknownID until after this session finishes the pre-connect and the master session transmits the correct sessionID.
2) When GetPreConnectStatus() returns true after this session node starts a join then this session node is in a pre-connect state.
3) This node will send one or more user defined packets that signal that the session wants to exchange certain pre-connect data to the master session using DataSendToSession() and session ID kXPSessionUnknownID. Using the reliable packet type is recommended but not mandatory.
4) The master session will receive user data packets and detecting that pre-connect data has been received will in reply send a user data message to the effect that it has received this information.
5) The joining node receives pre-connect data from the master session, verifies the data and either completes the pre-connect by calling PreConnectHasFinished() or uses Disconnect() to abort the connection.
| enable | Set this to be true to enable the pre-connect mechanism for this session node. If false then the session node will discard all pre-connect packets and the preconnection mechanism is assumed to be disabled. The default is false. |
| virtual bool GetPreConnect | ( | void | ) | [pure virtual] |
Gets the status of the pre-connect mechanism for this session node.
| virtual void PreConnectHasFinished | ( | void | ) | [pure virtual] |
If the pre-connect mechanism is enabled then this function must be called by the joining session node when packets have been exchanged to the satisfaction of the joining session node.
| virtual void SetAutomaticPacketCompression | ( | const bool | enable = false |
) | [pure virtual] |
Enables or disables the automatic packet compression test. If enabled XPSession will test each packet sent to see if it can be compressed and if there is a space saving then the packet is compressed before sending.
| enable | Enable or disable automatic packet compression. The default is false to disable automatic packet compression. |
| virtual bool GetAutomaticPacketCompression | ( | void | ) | [pure virtual] |
Gets the value configured by SetAutomaticPacketCompression()
| virtual void GetCompressionStatistics | ( | int *const | before = 0, |
|
| int *const | after = 0, |
|||
| const bool | reset = false | |||
| ) | [pure virtual] |
Gets the compression statistics totals for packets sent from this session node.
| before | The total number of bytes before compression. This can be null. | |
| after | The total number of bytes after compression. This can be null. | |
| reset | If true, after returning the information to the caller both totals are reset back to zero. The default value is false. |
| virtual void GetMergedStatistics | ( | int *const | sent = 0, |
|
| int *const | received = 0, |
|||
| const bool | reset = false | |||
| ) | [pure virtual] |
Gets the merged packet statistics totals for connections managed by this session node.
Note: This function can take some time to execute when there are hundreds of connected users.
| sent | The total number of merged sent packets. This can be null. | |
| received | The total number of merged sent packets. This can be null. | |
| reset | If true, after returning the information to the caller both totals are reset back to zero. The default value is false. |
| virtual int GetMasterSessionID | ( | void | ) | [pure virtual] |
Gets the master session unique ID. If the session is not connected then the return value is kXPSessionUnknownID.
| virtual std::string GetURLFromSessionID | ( | const int | sessionID | ) | [pure virtual] |
Attempts to resolve the URL of the session unique ID from the point of view of this session node. If the session unique ID is not known to the session then the result is a null string. If the session unique ID is not directly connected to this node, for example the spider connection was broken, then this function is not guaranteed to produce a URL and can return a null string.
| virtual void SetClientOnly | ( | const bool | isClient = false |
) | [pure virtual] |
Sets the client only flag for this session node. The default value is false which means this node will get joiner and leaver messages. If this is set to be true then this node will only get joiner/leaver messages for spider nodes or nodes that can become master nodes. This must not be changed after the session is used for joining a session. Setting this to option to be true also automatically sets SetCanBecomeMaster() and SetCanSpider() to be false.
| isClient | The default value is false. |
| virtual bool GetClientOnly | ( | void | ) | [pure virtual] |
Gets the client only configuration set by SetClientOnly().
| virtual bool GetBandwidthFromSessionID | ( | const int | sessionID, | |
| Transport::Bandwidth *const | bandwidth, | |||
| int *const | output, | |||
| int *const | input | |||
| ) | [pure virtual] |
Attempts to read the configured bandwidth for a route to a specific session ID. If the session ID is not directly connected to this node then this function will return false and the contents of the output and input pointers will be left unchanged. If this node can supply bandwidth information about a session ID then this function will return true and the bandwidth, output, input pointers will contain the values as used by SetBandwidthLimit(), SetMaximumOutputBandwidth() and SetMaximumInputBandwidth(). Note that output and input bandwidth will appear to be exchanged because the output of one end of transport connection is really the input of the other end of the connection.
Note: This function can take some time to execute when there are hundreds of connected users.
| sessionID | The session ID of the required node. | |
| bandwidth | A pointer to accept the Transport::Bandwidth value, this can be null. | |
| output | A pointer to accept the output bandwidth value, this can be null. | |
| input | A pointer to accept the input bandwidth value, this can be null. |
| virtual void SetAllowConnections | ( | const bool | allow = true |
) | [pure virtual] |
Enables or disables any further connection attempts to this session.
| allow | Set this to be true to allow connections to this session. False will stop any further connection attempts to this session and the connecting session will get kXPSession_ETRANSPORT_CLOSED from GetSessionErrorReason(). |
| virtual bool GetAllowConnections | ( | void | ) | [pure virtual] |
Returns the value configured by SetAllowConnections() the value.
| virtual void SetNodeBuffers | ( | const bool | enable = false |
) | [pure virtual] |
Enables or disables buffering for this session node. With buffering enabled extra memory is used to improve multi-threaded performance when this node is used by another thread.
| enable | The default is false which disables extra buffering. |
| virtual bool GetNodeBuffers | ( | void | ) | [pure virtual] |
Returns the value configured by SetNodeBuffers()
1.5.3