|
| PhotonPeer (PhotonListener &listener, nByte connectionProtocol=ConnectionProtocol::DEFAULT, nByte serializationProtocol=Common::SerializationProtocol::DEFAULT) |
|
virtual | ~PhotonPeer (void) |
|
virtual bool | connect (const Common::JString &ipAddr, const Common::JString &appID=Common::JString()) |
|
template<typename Ftype > |
bool | connect (const Common::JString &ipAddr, const Common::JString &appID, const Ftype &customData) |
|
template<typename Ftype > |
bool | connect (const Common::JString &ipAddr, const Common::JString &appID, const Ftype pCustomDataArray, int arrSize) |
|
template<typename Ftype > |
bool | connect (const Common::JString &ipAddr, const Common::JString &appID, const Ftype pCustomDataArray, const int *pArrSizes) |
|
virtual void | disconnect (void) |
|
virtual void | service (bool dispatchIncomingCommands=true) |
|
virtual void | serviceBasic (void) |
|
virtual bool | opCustom (const OperationRequest &operationRequest, bool sendReliable, nByte channelID=0, bool encrypt=false) |
|
virtual bool | sendOutgoingCommands (void) |
|
virtual bool | sendAcksOnly (void) |
|
virtual bool | dispatchIncomingCommands (void) |
|
virtual bool | establishEncryption (void) |
|
virtual void | fetchServerTimestamp (void) |
|
virtual void | resetTrafficStats (void) |
|
virtual void | resetTrafficStatsMaximumCounters (void) |
|
virtual Common::JString | vitalStatsToString (bool all) const |
|
virtual void | pingServer (const Common::JString &address, unsigned int pingAttempts) |
|
virtual void | initUserDataEncryption (const Common::JVector< nByte > &secret) |
|
virtual void | initUDPEncryption (const Common::JVector< nByte > &encryptSecret) |
|
PhotonListener * | getListener (void) |
|
int | getServerTimeOffset (void) const |
|
int | getServerTime (void) const |
|
int | getBytesOut (void) const |
|
int | getBytesIn (void) const |
|
int | getByteCountCurrentDispatch (void) const |
|
int | getByteCountLastOperation (void) const |
|
int | getPeerState (void) const |
|
int | getSentCountAllowance (void) const |
|
void | setSentCountAllowance (int sentCountAllowance) |
|
int | getTimePingInterval (void) const |
|
void | setTimePingInterval (int timePingInterval) |
|
int | getRoundTripTime (void) const |
|
int | getRoundTripTimeVariance (void) const |
|
int | getTimestampOfLastSocketReceive (void) const |
|
int | getDebugOutputLevel (void) const |
|
bool | setDebugOutputLevel (int debugLevel) |
|
const Common::LogFormatOptions & | getLogFormatOptions (void) const |
|
void | setLogFormatOptions (const Common::LogFormatOptions &formatOptions) |
|
int | getIncomingReliableCommandsCount (void) const |
|
short | getPeerID (void) const |
|
int | getDisconnectTimeout (void) const |
|
void | setDisconnectTimeout (int disconnectTimeout) |
|
int | getQueuedIncomingCommands (void) const |
|
int | getQueuedOutgoingCommands (void) const |
|
Common::JString | getServerAddress (void) const |
|
bool | getIsPayloadEncryptionAvailable (void) const |
|
bool | getIsEncryptionAvailable (void) const |
|
int | getResentReliableCommands (void) const |
|
int | getLimitOfUnreliableCommands (void) const |
|
void | setLimitOfUnreliableCommands (int value) |
|
bool | getCRCEnabled (void) const |
|
void | setCRCEnabled (bool crcEnabled) |
|
int | getPacketLossByCRC (void) const |
|
bool | getTrafficStatsEnabled (void) const |
|
void | setTrafficStatsEnabled (bool trafficStasEnabled) |
|
int | getTrafficStatsElapsedMs (void) const |
|
const TrafficStats & | getTrafficStatsIncoming (void) const |
|
const TrafficStats & | getTrafficStatsOutgoing (void) const |
|
const TrafficStatsGameLevel & | getTrafficStatsGameLevel (void) const |
|
nByte | getQuickResendAttempts (void) const |
|
void | setQuickResendAttempts (nByte quickResendAttempts) |
|
nByte | getConnectionProtocol (void) const |
|
void | setConnectionProtocol (nByte connectionProtocol) |
|
nByte | getChannelCountUserChannels (void) const |
|
nByte | getSerializationProtocol (void) const |
|
The PhotonPeer class provides an API for reliable and unreliable realtime communication.
PhotonPeer uses the callback interface PhotonListener that needs to be implemented by your application, to receive results and events from the Photon Server.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This overload accepts multidimensional arrays and NULL-pointers passed for parameter pCustomDataArray. The array that is passed for parameter pCustomDataArray has to be a pointer of the correct abstraction level, meaning a normal pointer for a singledimensional array, a doublepointer for a twodimensional array, a triplepointer for a threedimensional array and so on. For pCustomDataArray NULL pointers are only legal input, if pArrSizes[0] is 0. For pArrSizes NULL is no valid input.
- Parameters
-
ipAddr | Null terminated string containing IP address or domain name and optionally a port of server to connect. Should be in usual format: "address[:port]", for example: "192.168.0.1:5055" or "udp.gameserver.com". If no port is given, port 5055 will be used by default. |
appID | the appID (default: an empty string) |
pCustomDataArray | custom data to send to the server when initializing the connection - has to be provided in the form of an array of one of the supported data types, specified at Table of Datatypes |
pArrSizes | the element counts for every dimension of the custom data array - the element count of this array has to match the dimensions of the custom data array |
void service |
( |
bool |
dispatchIncomingCommands = true | ) |
|
|
virtual |
This function executes the PhotonPeer internal processes. Call this regularly!
This function is meant to be called frequently, like once per game loop. It handles the internal calls for keeping the PhotonPeer communication alive, and will take care of sending all local outgoing acknowledgements and messages, as well as dispatching incoming messages to the application and firing the corresponding callbacks. Internally service() calls the following functions:
- serviceBasic()
- dispatchIncomingCommands() (called within a loop until all incoming commands have been dispatched.)
- sendOutgoingCommands() (called within a loop until everything queued for sending has been sent.)
service() is provided for convenience. If you need to tweak the performance, you can ignore service() and call its three subfunctions directly with individual time intervals, to gain more control over the internal communication process. For instance, calling sendOutgoingCommands() more rarely will result in less packets to be generated, as more commands will be accumulated into a single packet. See sendOutgoingCommands() for more information on efficiency.
For situations where you want to keep the connection alive, but can't process incoming messages (e.g. when loading a level), you can temporarily pass false for parameter dispatchIncomingCommands to skip the calls to dispatchIncomingCommands(). Incoming commands will be stored in the incoming queue until they are dispatched again.
- Parameters
-
bool sendOutgoingCommands |
( |
void |
| ) |
|
|
virtual |
This function initiates the transmission of outgoing commands.
Any Photon function that generates messages will store these messages as a "command" in an outgoing queue for later transmission. Commands can either be explicitly created operations generated for example by opCustom() or internally generated messages like acknowledgements for reliable messages from other players. sendOutgoingCommands() will initiate the data transmission by passing the outgoing commands to the system's sockets for immediate transmission.
In case of UDP sendOutgoingCommands() will also split the commands into multiple packets if needed and aggregate multiple commands together into one packet, if possible. Because of the latter calling sendOutgoingcommands() more rarely will result in less overhead, as there will be fewer packets for the clients to be sent and processed. The underlying platform can also limit the frequency in which outgoing packets can be sent and received. The downside of lower sending frequencies is a higher latency, until messages are exchanged and acknowledged, which may lead to a jerky gameplay.
To help you keeping track of the incoming and outgoing queues at development time and adjust your sending frequency, there will be a warning message sent to your debugReturn callback if a queue has exceeded the warning threshold.
- Note
- While service() is calling serviceBasic() implicitly, you will have to regularly call it yourself explictly , when you use sendOutgoingCommands() and dispatchIncomingCommands() directly instead.
Usually you don't have to call sendOutgoingCommands() this explicitly, as this is done within service().
- See also
- service()
bool dispatchIncomingCommands |
( |
void |
| ) |
|
|
virtual |
Checks for incoming commands waiting in the queue, and dispatches a single command to the application.
Dispatching means, that if the command is an operation response or an event, the appropriate callback function will be called). dispatchIncomingCommands() will also take care of generating and queuing acknowledgments for incoming reliable commands. Please note that this function will only dispatch one command per all. If you want to dispatch every single command which is waiting in the queue, call dipatchIncomingCommands() within a while loop, until its return code is false.
- Note
- While service() is calling serviceBasic() implicitly, you will have to regularly call it yourself explictly, when you use sendOutgoingCommands() and dispatchIncomingCommands() directly instead.
- Returns
- true if it has successfully dispatched a command, false otherwise (for example, when there has not been any command left in the queue, waiting for dispatching).
- See also
- service()
void pingServer |
( |
const Common::JString & |
address, |
|
|
unsigned int |
pingAttempts |
|
) |
| |
|
virtual |
Sends a ping signal to the specified address.
Each call to this function results in a number of calls to PhotonListener::onPingResponse() that equals the value which has been passed for parameter pingAttempts.
This function can be used to ping multiple Photon servers and determine the one with the lowest latency.
As the latency of the same server may vary it can make sense to send multiple ping attempts. In that case the next attempt gets sent when either the servers response for the previous attempt has been received or when that previous attempt has timed out.
Multiple calls to this function do not get queued, but run in parallel.
A valid Photon server must run at the specified address.
- Note
- This function is not available on platforms that do not support those parts of the stdlib that have been introduced with C++ 11.
-
This function is not available on platforms that do not support multi-threading.
-
If the connection protocol of the PhotonPeer instance is WS or WSS, then this function uses UDP for pinging, otherwise it uses the connection protocol of the PhotonPeer instance for pinging. If you include a port number in the 'address' string and the connection protocol of the PhotonPeer instance is WS or WSS, then that port number needs to be the UDP port of the server and not its WS or WSS port.
- Parameters
-
address | the address, which should be pinged |
pingAttempts | the amount of ping signals to send |
- See also
- PhotonListener::onPingResponse()
int getServerTimeOffset |
( |
void |
| ) |
const |
- Returns
- the difference between the local uptime and the Photon Server's system time in ms.
In real-time games it's often useful to relate game events to a global common timeline, that's valid for all players and independent from derivations throughout the clients' system times. The Photon Server's System Time can serve as this reference time. The serverTimeOffset represents the difference between the client's local system time and the Photon server's system time.
ServerTime = serverTimeOffset + GETTIMEMS()
The serverTimeOffset is fetched shortly after connect by Photon. Use GETTIMEMS() to get your local time in ms. You can let Photon refetch the offset by calling fetchServerTimestamp(). The ServerTimeOffset will be 0 until shortly after initial connect.
void setCRCEnabled |
( |
bool |
crcEnabled | ) |
|
Enables or disables CRC. While not connected, this controls if the next connection(s) should use a per-package CRC checksum. If the client is in another state than 'connected', then this function has no effect except for logging an error.
While turned on, the client and server will add a CRC checksum to every sent package. The checksum enables both sides to detect and ignore packages that were corrupted during transfer. Corrupted packages have the same impact as lost packages: They require a re-send, adding a delay and could lead to timeouts. Building the checksum has a low processing overhead but increases integrity of sent and received data. Packages discarded due to failed CRC checks are counted in PhotonPeer.PacketLossByCRC.
- Note
- This only has effect for UDP connections.
-
This does not have any effect for connections that use UDP datagram encryption (which always use a built-in checksum).
- See also
- getCRCEnabled