Photon .NET Client API 4.1.4.8

Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Properties | Events | List of all members
ExitGames.Client.Photon.PhotonPeer Class Reference

Instances of the PhotonPeer class are used to connect to a Photon server and communicate with it. More...

Inheritance diagram for ExitGames.Client.Photon.PhotonPeer:
Photon.Chat.ChatPeer Photon.Realtime.LoadBalancingPeer

Public Member Functions

string CommandLogToString ()
 Obsolete and ignored. Converts the CommandLog into a readable table-like string with summary. More...
 
void TrafficStatsReset ()
 Creates new instances of TrafficStats and starts a new timer for those. More...
 
string VitalStatsToString (bool all)
 Returns a string of the most interesting connection statistics. When you have issues on the client side, these might contain hints about the issue's cause. More...
 
 PhotonPeer (ConnectionProtocol protocolType)
 Creates a new PhotonPeer with specified transport protocol (without a IPhotonPeerListener). More...
 
 PhotonPeer (IPhotonPeerListener listener, ConnectionProtocol protocolType)
 Creates a new PhotonPeer instance to communicate with Photon and selects the transport protocol. We recommend UDP. More...
 
virtual bool Connect (string serverAddress, string appId, object custom=null)
 Starts connecting to the given Photon server. Non-blocking. More...
 
virtual bool Connect (string serverAddress, string proxyServerAddress, string appId, object custom)
 Starts connecting to the given Photon server. Non-blocking. More...
 
virtual void Disconnect ()
 This method initiates a mutual disconnect between this client and the server. More...
 
virtual void StopThread ()
 This method immediately closes a connection (pure client side) and ends related listening Threads. More...
 
virtual void FetchServerTimestamp ()
 This will fetch the server's timestamp and update the approximation for property ServerTimeInMilliseconds. More...
 
bool EstablishEncryption ()
 This method creates a public key for this client and exchanges it with the server. More...
 
bool InitDatagramEncryption (byte[] encryptionSecret, byte[] hmacSecret, bool randomizedSequenceNumbers=false, bool chaningModeGCM=false)
 Initializes Datagram Encryption. Optionally, the EncryptorType is being used, if set. More...
 
void InitPayloadEncryption (byte[] secret)
 Photon's Payload Encryption secret may be set by a response from the server. More...
 
virtual void Service ()
 This method excutes DispatchIncomingCommands and SendOutgoingCommands in your application Thread-context. More...
 
virtual bool SendOutgoingCommands ()
 Creates and sends a UDP/TCP package with outgoing commands (operations and acknowledgements). Also called by Service(). More...
 
virtual bool SendAcksOnly ()
 
virtual bool DispatchIncomingCommands ()
 Dispatching received messages (commands), causes callbacks for events, responses and state changes within a IPhotonPeerListener. More...
 
virtual bool SendOperation (byte operationCode, Dictionary< byte, object > operationParameters, SendOptions sendOptions)
 Prepares your operation (code and parameters) to be sent to the Photon Server with specified SendOptions. More...
 
virtual bool SendOperation (byte operationCode, ParameterDictionary operationParameters, SendOptions sendOptions)
 

Static Public Member Functions

static void MessageBufferPoolTrim (int countOfBuffers)
 Sets a new (temporary) size of the MessageBufferPool to reuse memory where possible. More...
 
static int MessageBufferPoolSize ()
 
static bool RegisterType (Type customType, byte code, SerializeMethod serializeMethod, DeserializeMethod constructor)
 Registers new types/classes for de/serialization and the fitting methods to call for this type. More...
 
static bool RegisterType (Type customType, byte code, SerializeStreamMethod serializeMethod, DeserializeStreamMethod constructor)
 

Public Attributes

int WarningSize
 The WarningSize was used test all message queues for congestion. More...
 
int CommandLogSize
 Obsolete and ignored. Size of CommandLog. Default is 0, no logging. More...
 
TargetFrameworks TargetFramework = TargetFrameworks.Net35
 Target framework this dll was built for. More...
 
bool RemoveAppIdFromWebSocketPath
 Can be used to remove/hide the AppId from websocket connect paths. More...
 
Dictionary< ConnectionProtocol, Type > SocketImplementationConfig
 Optional definition of IPhotonSocket type per ConnectionProtocol. More...
 
DebugLevel DebugOut = DebugLevel.ERROR
 Sets the level (and amount) of debug output provided by the library. More...
 
bool SendInCreationOrder = true
 This debug setting enables a new send-ordering for commands. Defaults to true and commands are sent in the order they are created. Set to false to use Enet ordering. More...
 
ITrafficRecorder TrafficRecorder
 If set, the TrafficRecorder will be used to capture all traffic. More...
 
byte ChannelCount = 2
 Gets / sets the number of channels available in UDP connections with Photon. Photon Channels are only supported for UDP. The default ChannelCount is 2. Channel IDs start with 0 and 255 is a internal channel. More...
 
bool EnableEncryptedFlag = false
 Enables the client so send the "encrypted" flag on secure connections. Incompatible with Server SDK 4.x. More...
 
int SentCountAllowance = 7
 Number of send retries before a peer is considered lost/disconnected. Default: 7. More...
 
int InitialResendTimeMax = 400
 Caps the initial timing for repeats of reliable commands. In milliseconds. Default: 400ms. More...
 
int TimePingInterval = 1000
 Sets the time between pings being sent automatically. They measure the roundtrip time and keep connections from closing. Default: 1000. More...
 

Static Public Attributes

const bool NativeDatagramEncrypt = true
 Where dynamic linking is available, this library will attempt to load a native Photon "Encryptor" plugin library for "Datagram Encryption". More...
 
const bool NoSocket = false
 False if this library build contains C# Socket code. If true, you must set some type as SocketImplementation before connecting. More...
 
const bool DebugBuild = false
 True if the library was compiled with DEBUG setting. More...
 
const int NativeEncryptorApiVersion = 2
 Version of the Native Encryptor API compiled into this assembly. Defines which PhotonEncryptorPlugin needs to be used. More...
 
static bool NoNativeCallbacks
 Global toggle to avoid callbacks from native plugins. Defaults to false, meaning: "callbacks enabled". More...
 
static int OutgoingStreamBufferSize = 1200
 Defines the initial size of an internally used StreamBuffer for Tcp. The StreamBuffer is used to aggregate operation into (less) send calls, which uses less resoures. More...
 
static bool AsyncKeyExchange = false
 Defines if Key Exchange for Encryption is done asynchronously in another thread. More...
 

Properties

int CommandBufferSize [get, set]
 No effect anymore. Removed without replacement. More...
 
int LimitOfUnreliableCommands [get, set]
 No effect anymore. Removed without replacement. More...
 
int LocalTimeInMilliSeconds [get]
 Gets a local timestamp in milliseconds by calling SupportClass.GetTickCount(). See LocalMsTimestampDelegate. More...
 
string ClientVersion [get]
 Version of this library as string. More...
 
static bool NativeSocketLibAvailable [get]
 Checks if a native library for network sockets (PhotonSocketPlugin.dll) is available. To use it, see remarks. More...
 
static bool NativePayloadEncryptionLibAvailable [get]
 Checks if native library for Payload Encryption (PhotonCryptoPlugin.dll) is available. Used automatically. More...
 
static bool NativeDatagramEncryptionLibAvailable [get]
 Checks if a native library for Datagram Encryption is available. To use it, see remarks. More...
 
SerializationProtocol SerializationProtocolType [get, set]
 Enables selection of a (Photon-)serialization protocol. Used in Connect methods. More...
 
Type SocketImplementation [get, set]
 Can be used to read the IPhotonSocket implementation at runtime (before connecting). More...
 
IPhotonPeerListener Listener [get, protected set]
 Gets the IPhotonPeerListener of this instance (set in constructor). Can be used in derived classes for Listener.DebugReturn(). More...
 
bool ReuseEventInstance [get, set]
 Option to make the PhotonPeer reuse a single EventData instance for all incoming events. More...
 
bool UseByteArraySlicePoolForEvents [get, set]
 Enables a deserialization optimization for incoming events. Defaults to false. More...
 
bool WrapIncomingStructs [get, set]
 Incoming struct types are wrapped in a pooled IWrapperStruct, rather than being cast to object. This eliminated allocations and garbage collection from boxing, however object that are wrapped structs will need to be cast to WrapperStruct<T> and their values extracted with (obj as WrapperStruct<T>).Value. More...
 
ByteArraySlicePool ByteArraySlicePool [get]
 Instance of a ByteArraySlicePool. UseByteArraySlicePoolForEvents defines if this PhotonPeer is using the pool for deserialization of byte[] in Photon events. More...
 
long BytesIn [get]
 Gets count of all bytes coming in (including headers, excluding UDP/TCP overhead) More...
 
long BytesOut [get]
 Gets count of all bytes going out (including headers, excluding UDP/TCP overhead) More...
 
int ByteCountCurrentDispatch [get]
 Gets the size of the dispatched event or operation-result in bytes. This value is set before OnEvent() or OnOperationResponse() is called (within DispatchIncomingCommands()). More...
 
string? CommandInfoCurrentDispatch [get]
 Returns the debug string of the event or operation-response currently being dispatched or string. Empty if none. More...
 
int ByteCountLastOperation [get]
 Gets the size of the last serialized operation call in bytes. The value includes all headers for this single operation but excludes those of UDP, Enet Package Headers and TCP. More...
 
bool EnableServerTracing [get, set]
 Debugging option to tell the Photon Server to log all datagrams. More...
 
byte QuickResendAttempts [get, set]
 Up to 4 resend attempts for a reliable command can be done in quick succession (after RTT+4*Variance). More...
 
PeerStateValue PeerState [get]
 This is the (low level) state of the connection to the server of a PhotonPeer. Managed internally and read-only. More...
 
string PeerID [get]
 This peer's ID as assigned by the server or 0 if not using UDP. Will be 0xFFFF before the client connects. More...
 
int QueuedIncomingCommands [get]
 Count of all currently received but not-yet-Dispatched reliable commands (events and operation results) from all channels. More...
 
int QueuedOutgoingCommands [get]
 Count of all commands currently queued as outgoing, including all channels and reliable, unreliable. More...
 
bool CrcEnabled [get, set]
 While not connected, this controls if the next connection(s) should use a per-package CRC checksum. More...
 
int PacketLossByCrc [get]
 Count of packages dropped due to failed CRC checks for this connection. More...
 
int PacketLossByChallenge [get]
 Count of packages dropped due to wrong challenge for this connection. More...
 
int SentReliableCommandsCount [get]
 Gets the count of sent but not yet acknowledged commands (for UDP connections). More...
 
int? ResentReliableCommands [get]
 Count of commands that got repeated (due to local repeat-timing before an ACK was received). More...
 
int DisconnectTimeout [get, set]
 Time in milliseconds before any sent reliable command triggers a timeout disconnect, unless acknowledged by the receiver. Default: 10000. More...
 
int? ServerTimeInMilliSeconds [get]
 Approximated Environment.TickCount value of server (while connected). More...
 
SupportClass.IntegerMillisecondsDelegate LocalMsTimestampDelegate [set]
 This setter for the (local-) timestamp delegate replaces the default Environment.TickCount with any equal function. More...
 
int ConnectionTime [get]
 The internally used "per connection" time value, which is updated infrequently, when the library executes some connectio-related tasks. More...
 
int LastSendAckTime [get]
 The last ConnectionTime value, when some ACKs were sent out by this client. More...
 
int LastSendOutgoingTime [get]
 The last ConnectionTime value, when SendOutgoingCommands actually checked outgoing queues to send them. Must be connected. More...
 
int LongestSentCall [get, set]
 Measures the maximum milliseconds spent in PhotonSocket.Send(). More...
 
int RoundTripTime [get]
 Time until a reliable command is acknowledged by the server. More...
 
int RoundTripTimeVariance [get]
 Changes of the roundtriptime as variance value. Gives a hint about how much the time is changing. More...
 
int LastRoundTripTime [get]
 The last measured roundtrip time for this connection. More...
 
int TimestampOfLastSocketReceive [get]
 Timestamp of the last time anything (!) was received from the server (including low level Ping, ACKs, events and operation-returns). More...
 
string ServerAddress [get]
 The server address which was used in PhotonPeer.Connect() or null (before Connect() was called). More...
 
string ServerIpAddress [get]
 Contains the IP address of the previously resolved ServerAddress (or empty, if address wasn't resolved with the internal methods). More...
 
ConnectionProtocol UsedProtocol [get]
 The protocol this peer is currently connected/connecting with (or 0). More...
 
ConnectionProtocol TransportProtocol [get, set]
 This is the transport protocol to be used for next connect (see remarks). More...
 
virtual bool IsSimulationEnabled [get, set]
 Gets or sets the network simulation "enabled" setting. Changing this value also locks this peer's sending and when setting false, the internally used queues are executed (so setting to false can take some cycles). More...
 
NetworkSimulationSet NetworkSimulationSettings [get]
 Gets the settings for built-in Network Simulation for this peer instance while IsSimulationEnabled will enable or disable them. Once obtained, the settings can be modified by changing the properties. More...
 
int MaximumTransferUnit [get, set]
 The Maximum Trasfer Unit (MTU) defines the (network-level) packet-content size that is guaranteed to arrive at the server in one piece. The Photon Protocol uses this size to split larger data into packets and for receive-buffers of packets. More...
 
bool IsEncryptionAvailable [get]
 This property is set internally, when OpExchangeKeysForEncryption successfully finished. While it's true, encryption can be used for operations. More...
 
bool IsSendingOnlyAcks [get, set]
 While true, the peer will not send any other commands except ACKs (used in UDP connections). More...
 
TrafficStats TrafficStatsIncoming [get, set]
 Gets the byte-count of incoming "low level" messages, which are either Enet Commands or Tcp Messages. These include all headers, except those of the underlying internet protocol Udp or Tcp. More...
 
TrafficStats TrafficStatsOutgoing [get, set]
 Gets the byte-count of outgoing "low level" messages, which are either Enet Commands or Tcp Messages. These include all headers, except those of the underlying internet protocol Udp or Tcp. More...
 
TrafficStatsGameLevel TrafficStatsGameLevel [get, set]
 Gets a statistic of incoming and outgoing traffic, split by operation, operation-result and event. More...
 
long? TrafficStatsElapsedMs [get]
 Returns the count of milliseconds the stats are enabled for tracking. More...
 
bool TrafficStatsEnabled [get, set]
 Enables or disables collection of statistics in TrafficStatsIncoming, TrafficStatsOutgoing and TrafficstatsGameLevel. More...
 
Type EncryptorType [get, set]
 Setter for the Datagram Encryptor instance. Used at next connect. More...
 
int CountDiscarded [get, set]
 Count of unreliable commands being discarded in case this client already dispatched a command that was newer (higher sequence number). More...
 
int DeltaUnreliableNumber [get, set]
 Set per dispatch in DispatchIncomingCommands to: commandUnreliableSequenceNumber - channel.incomingUnreliableSequenceNumber. Indicates how big the (sequence)gap is, compared to the last dispatched unreliable command. More...
 

Events

Action< DisconnectMessageOnDisconnectMessage
 Called when the client received a Disconnect Message from the server. Signals an error and provides a message to debug the case. More...
 

Detailed Description

Instances of the PhotonPeer class are used to connect to a Photon server and communicate with it.

A PhotonPeer instance allows communication with the Photon Server, which in turn distributes messages to other PhotonPeer clients.

An application can use more than one PhotonPeer instance, which are treated as separate users on the server. Each should have its own listener instance, to separate the operations, callbacks and events.

Constructor & Destructor Documentation

◆ PhotonPeer() [1/2]

ExitGames.Client.Photon.PhotonPeer.PhotonPeer ( ConnectionProtocol  protocolType)
inline

Creates a new PhotonPeer with specified transport protocol (without a IPhotonPeerListener).

Make sure to set the Listener, before using the peer.

◆ PhotonPeer() [2/2]

ExitGames.Client.Photon.PhotonPeer.PhotonPeer ( IPhotonPeerListener  listener,
ConnectionProtocol  protocolType 
)
inline

Creates a new PhotonPeer instance to communicate with Photon and selects the transport protocol. We recommend UDP.

Parameters
listenera IPhotonPeerListener implementation
protocolTypeProtocol to use to connect to Photon.

Member Function Documentation

◆ CommandLogToString()

string ExitGames.Client.Photon.PhotonPeer.CommandLogToString ( )
inline

Obsolete and ignored. Converts the CommandLog into a readable table-like string with summary.

◆ Connect() [1/2]

virtual bool ExitGames.Client.Photon.PhotonPeer.Connect ( string  serverAddress,
string  appId,
object  custom = null 
)
inlinevirtual

Starts connecting to the given Photon server. Non-blocking.

Connecting to the Photon server is done asynchronous. Unless an error happens right away (and this returns false), wait for the call of IPhotonPeerListener.OnStatusChanged.

Parameters
serverAddressAddress of a Photon server as IP:port or hostname. WebSocket connections must contain a scheme (ws:// or wss://).
appIdThe ID of the app to use. Typically this is a guid (for the Photon Cloud). Max 32 characters.
customOptional custom data to be used by server during peer creation. If used for authentication, the server is able to reject a client without creating a peer. Must be a serializable data type of Photon.
Returns
True if a connection attempt will be made. False if some error could be detected early-on.

◆ Connect() [2/2]

virtual bool ExitGames.Client.Photon.PhotonPeer.Connect ( string  serverAddress,
string  proxyServerAddress,
string  appId,
object  custom 
)
inlinevirtual

Starts connecting to the given Photon server. Non-blocking.

Connecting to the Photon server is done asynchronous. Unless an error happens right away (and this returns false), wait for the call of IPhotonPeerListener.OnStatusChanged.

Parameters
serverAddressAddress of a Photon server as IP:port or hostname. WebSocket connections must contain a scheme (ws:// or wss://).
proxyServerAddressOptional address of a proxy server. Only used by WebSocket connections. Set null to use none.
appIdThe ID of the app to use. Typically this is a guid (for the Photon Cloud). Max 32 characters.
customOptional custom data to be used by server during peer creation. If used for authentication, the server is able to reject a client without creating a peer. Must be a serializable data type of Photon.
Returns
True if a connection attempt will be made. False if some error could be detected early-on.

◆ Disconnect()

virtual void ExitGames.Client.Photon.PhotonPeer.Disconnect ( )
inlinevirtual

This method initiates a mutual disconnect between this client and the server.

Calling this method does not immediately close a connection. Disconnect lets the server know that this client is no longer listening. For the server, this is a much faster way to detect that the client is gone but it requires the client to send a few final messages.

On completion, OnStatusChanged is called with the StatusCode.Disconnect.

If the client is disconnected already or the connection thread is stopped, then there is no callback.

The default server logic will leave any joined game and trigger the respective event.

◆ DispatchIncomingCommands()

virtual bool ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands ( )
inlinevirtual

Dispatching received messages (commands), causes callbacks for events, responses and state changes within a IPhotonPeerListener.

DispatchIncomingCommands only executes a single received command per call. If a command was dispatched, the return value is true and the method should be called again.

This method is called by Service() until currently available commands are dispatched. In general, this method should be called until it returns false. In a few cases, it might make sense to pause dispatching (if a certain state is reached and the app needs to load data, before it should handle new events).

The callbacks to the peer's IPhotonPeerListener are executed in the same thread that is calling DispatchIncomingCommands. This makes things easier in a game loop: Event execution won't clash with painting objects or the game logic.

◆ EstablishEncryption()

bool ExitGames.Client.Photon.PhotonPeer.EstablishEncryption ( )
inline

This method creates a public key for this client and exchanges it with the server.

Encryption is not instantly available but calls OnStatusChanged when it finishes. Check for StatusCode EncryptionEstablished and EncryptionFailedToEstablish.

Calling this method sets IsEncryptionAvailable to false. This method must be called before the "encrypt" parameter of OpCustom can be used.

Returns
If operation could be enqueued for sending

◆ FetchServerTimestamp()

virtual void ExitGames.Client.Photon.PhotonPeer.FetchServerTimestamp ( )
inlinevirtual

This will fetch the server's timestamp and update the approximation for property ServerTimeInMilliseconds.

The server time approximation will NOT become more accurate by repeated calls. Accuracy currently depends on a single roundtrip which is done as fast as possible.

The command used for this is immediately acknowledged by the server. This makes sure the roundtrip time is low and the timestamp + rountriptime / 2 is close to the original value.

◆ InitDatagramEncryption()

bool ExitGames.Client.Photon.PhotonPeer.InitDatagramEncryption ( byte[]  encryptionSecret,
byte[]  hmacSecret,
bool  randomizedSequenceNumbers = false,
bool  chaningModeGCM = false 
)
inline

Initializes Datagram Encryption. Optionally, the EncryptorType is being used, if set.

Parameters
encryptionSecretsecret used to cipher udp packets
hmacSecretsecret used for authentication of udp packets

◆ InitPayloadEncryption()

void ExitGames.Client.Photon.PhotonPeer.InitPayloadEncryption ( byte[]  secret)
inline

Photon's Payload Encryption secret may be set by a response from the server.

Parameters
secretThe secret in form of a byte[].

◆ MessageBufferPoolSize()

static int ExitGames.Client.Photon.PhotonPeer.MessageBufferPoolSize ( )
inlinestatic

◆ MessageBufferPoolTrim()

static void ExitGames.Client.Photon.PhotonPeer.MessageBufferPoolTrim ( int  countOfBuffers)
inlinestatic

Sets a new (temporary) size of the MessageBufferPool to reuse memory where possible.

The MessageBufferPool is a Queue<StreamBuffer> for performance reasons. This methods dequeues from the MessageBufferPool to get the Count equal to countOfBuffers, then it calls MessageBufferPool.TrimExcess().

Parameters
countOfBuffersNew size of the pool. Clears the pool if <= 0.

◆ RegisterType() [1/2]

static bool ExitGames.Client.Photon.PhotonPeer.RegisterType ( Type  customType,
byte  code,
SerializeMethod  serializeMethod,
DeserializeMethod  constructor 
)
inlinestatic

Registers new types/classes for de/serialization and the fitting methods to call for this type.

SerializeMethod and DeserializeMethod are complementary: Feed the product of serializeMethod to the constructor, to get a comparable instance of the object.

After registering a Type, it can be used in events and operations and will be serialized like built-in types.

Parameters
customTypeType (class) to register.
codeA byte-code used as shortcut during transfer of this Type.
serializeMethodMethod delegate to create a byte[] from a customType instance.
constructorMethod delegate to create instances of customType's from byte[].
Returns
If the Type was registered successfully.

◆ RegisterType() [2/2]

static bool ExitGames.Client.Photon.PhotonPeer.RegisterType ( Type  customType,
byte  code,
SerializeStreamMethod  serializeMethod,
DeserializeStreamMethod  constructor 
)
inlinestatic

◆ SendAcksOnly()

virtual bool ExitGames.Client.Photon.PhotonPeer.SendAcksOnly ( )
inlinevirtual

◆ SendOperation() [1/2]

virtual bool ExitGames.Client.Photon.PhotonPeer.SendOperation ( byte  operationCode,
Dictionary< byte, object >  operationParameters,
SendOptions  sendOptions 
)
inlinevirtual

Prepares your operation (code and parameters) to be sent to the Photon Server with specified SendOptions.

This method serializes and enqueues the operation right away while the actual sending happens later. To be able to aggregate operations/messages, the Photon client sends packages only when you call SendOutgoingCommands().

The sendOptions specify how the operation gets sent exactly. Keep in mind that some transport protocols don't support unreliable or unsequenced transport. In that case, the sendOptions might be ignored.

The operationCode must be known by the server's logic or won't be processed. In almost all cases, sending an operation will result in a OperationResponse (see: IPhotonPeerListener.OnOperationResponse).

Parameters
operationCodeOperations are handled by their byte-typed code. The codes are defined in the Realtime API (a.k.a. LoadBalancing API).
operationParametersContaining parameters as key-value pair. The key is byte-typed, while the value is any serializable datatype.
sendOptionsWraps up DeliveryMode (reliability), Encryption and Channel values for sending.
Returns
If operation could be enqueued for sending.

◆ SendOperation() [2/2]

virtual bool ExitGames.Client.Photon.PhotonPeer.SendOperation ( byte  operationCode,
ParameterDictionary  operationParameters,
SendOptions  sendOptions 
)
inlinevirtual

◆ SendOutgoingCommands()

virtual bool ExitGames.Client.Photon.PhotonPeer.SendOutgoingCommands ( )
inlinevirtual

Creates and sends a UDP/TCP package with outgoing commands (operations and acknowledgements). Also called by Service().

As the Photon library does not create any UDP/TCP packages by itself. Instead, the application fully controls how many packages are sent and when. A tradeoff, an application will lose connection, if it is no longer calling SendOutgoingCommands or Service.

If multiple operations and ACKs are waiting to be sent, they will be aggregated into one package. The package fills in this order: ACKs for received commands A "Ping" - only if no reliable data was sent for a while Starting with the lowest Channel-Nr: Reliable Commands in channel Unreliable Commands in channel

This gives a higher priority to lower channels.

A longer interval between sends will lower the overhead per sent operation but increase the internal delay (which adds "lag").

Call this 2..20 times per second (depending on your target platform).

Returns
The if commands are not yet sent. Udp limits it's package size, Tcp doesnt.

◆ Service()

virtual void ExitGames.Client.Photon.PhotonPeer.Service ( )
inlinevirtual

This method excutes DispatchIncomingCommands and SendOutgoingCommands in your application Thread-context.

The Photon client libraries are designed to fit easily into a game or application. The application is in control of the context (thread) in which incoming events and responses are executed and has full control of the creation of UDP/TCP packages.

Sending packages and dispatching received messages are two separate tasks. Service combines them into one method at the cost of control. It calls DispatchIncomingCommands and SendOutgoingCommands.

Call this method regularly (2..20 times a second).

This will Dispatch ANY remaining buffered responses and events AND will send queued outgoing commands. Fewer calls might be more effective if a device cannot send many packets per second, as multiple operations might be combined into one package.

You could replace Service by:

while (DispatchIncomingCommands()); //Dispatch until everything is Dispatched...
SendOutgoingCommands(); //Send a UDP/TCP package with outgoing messages
See also
PhotonPeer.DispatchIncomingCommands, PhotonPeer.SendOutgoingCommands

◆ StopThread()

virtual void ExitGames.Client.Photon.PhotonPeer.StopThread ( )
inlinevirtual

This method immediately closes a connection (pure client side) and ends related listening Threads.

Unlike Disconnect, this method will simply stop to listen to the server. Udp connections will timeout. If the connections was open, this will trigger a callback to OnStatusChanged with code StatusCode.Disconnect.

◆ TrafficStatsReset()

void ExitGames.Client.Photon.PhotonPeer.TrafficStatsReset ( )
inline

Creates new instances of TrafficStats and starts a new timer for those.

◆ VitalStatsToString()

string ExitGames.Client.Photon.PhotonPeer.VitalStatsToString ( bool  all)
inline

Returns a string of the most interesting connection statistics. When you have issues on the client side, these might contain hints about the issue's cause.

Parameters
allIf true, Incoming and Outgoing low-level stats are included in the string.
Returns
Stats as string.

Member Data Documentation

◆ AsyncKeyExchange

bool ExitGames.Client.Photon.PhotonPeer.AsyncKeyExchange = false
static

Defines if Key Exchange for Encryption is done asynchronously in another thread.

◆ ChannelCount

byte ExitGames.Client.Photon.PhotonPeer.ChannelCount = 2

Gets / sets the number of channels available in UDP connections with Photon. Photon Channels are only supported for UDP. The default ChannelCount is 2. Channel IDs start with 0 and 255 is a internal channel.

◆ CommandLogSize

int ExitGames.Client.Photon.PhotonPeer.CommandLogSize

Obsolete and ignored. Size of CommandLog. Default is 0, no logging.

◆ DebugBuild

const bool ExitGames.Client.Photon.PhotonPeer.DebugBuild = false
static

True if the library was compiled with DEBUG setting.

◆ DebugOut

DebugLevel ExitGames.Client.Photon.PhotonPeer.DebugOut = DebugLevel.ERROR

Sets the level (and amount) of debug output provided by the library.

This affects the callbacks to IPhotonPeerListener.DebugReturn. Default Level: Error.

◆ EnableEncryptedFlag

bool ExitGames.Client.Photon.PhotonPeer.EnableEncryptedFlag = false

Enables the client so send the "encrypted" flag on secure connections. Incompatible with Server SDK 4.x.

◆ InitialResendTimeMax

int ExitGames.Client.Photon.PhotonPeer.InitialResendTimeMax = 400

Caps the initial timing for repeats of reliable commands. In milliseconds. Default: 400ms.

Unless acknowledged, reliable commands are repeated initially after: current roundTripTime + 4 * roundTripTimeVariance.

As this value can be very high when there was exceptional lag, InitialResendTimeMax makes sure that commands get repeated several times before they may trigger a timeout.

◆ NativeDatagramEncrypt

const bool ExitGames.Client.Photon.PhotonPeer.NativeDatagramEncrypt = true
static

Where dynamic linking is available, this library will attempt to load a native Photon "Encryptor" plugin library for "Datagram Encryption".

Fallback to a managed implementation. This value is always true.

◆ NativeEncryptorApiVersion

const int ExitGames.Client.Photon.PhotonPeer.NativeEncryptorApiVersion = 2
static

Version of the Native Encryptor API compiled into this assembly. Defines which PhotonEncryptorPlugin needs to be used.

◆ NoNativeCallbacks

bool ExitGames.Client.Photon.PhotonPeer.NoNativeCallbacks
static

Global toggle to avoid callbacks from native plugins. Defaults to false, meaning: "callbacks enabled".

Callbacks from native code will fail on some platforms, which is why you can disable them.

◆ NoSocket

const bool ExitGames.Client.Photon.PhotonPeer.NoSocket = false
static

False if this library build contains C# Socket code. If true, you must set some type as SocketImplementation before connecting.

◆ OutgoingStreamBufferSize

int ExitGames.Client.Photon.PhotonPeer.OutgoingStreamBufferSize = 1200
static

Defines the initial size of an internally used StreamBuffer for Tcp. The StreamBuffer is used to aggregate operation into (less) send calls, which uses less resoures.

The size is not restricing the buffer and does not affect when outgoing data is actually sent.

◆ RemoveAppIdFromWebSocketPath

bool ExitGames.Client.Photon.PhotonPeer.RemoveAppIdFromWebSocketPath

Can be used to remove/hide the AppId from websocket connect paths.

◆ SendInCreationOrder

bool ExitGames.Client.Photon.PhotonPeer.SendInCreationOrder = true

This debug setting enables a new send-ordering for commands. Defaults to true and commands are sent in the order they are created. Set to false to use Enet ordering.

◆ SentCountAllowance

int ExitGames.Client.Photon.PhotonPeer.SentCountAllowance = 7

Number of send retries before a peer is considered lost/disconnected. Default: 7.

The initial timeout countdown of a command is calculated by the current roundTripTime + 4 * roundTripTimeVariance. Please note that the timeout span until a command will be resent is not constant, but based on the roundtrip time at the initial sending, which will be doubled with every failed retry.

DisconnectTimeout and SentCountAllowance are competing settings: either might trigger a disconnect on the client first, depending on the values and Roundtrip Time.

◆ SocketImplementationConfig

Dictionary<ConnectionProtocol, Type> ExitGames.Client.Photon.PhotonPeer.SocketImplementationConfig

Optional definition of IPhotonSocket type per ConnectionProtocol.

Several platforms have special Socket implementations and slightly different APIs. To accomodate this, switching the socket implementation for a network protocol was made available. By default, UDP and TCP have socket implementations assigned.

If a native socket plugin is available (see: PhotonPeer.NativeSocketLibAvailable), the SocketNative class is used by default (with dynamic linking).

You only need to set the SocketImplementationConfig once, after creating a PhotonPeer and before connecting. If you switch the TransportProtocol, the correct implementation is being used.

◆ TargetFramework

TargetFrameworks ExitGames.Client.Photon.PhotonPeer.TargetFramework = TargetFrameworks.Net35

Target framework this dll was built for.

◆ TimePingInterval

int ExitGames.Client.Photon.PhotonPeer.TimePingInterval = 1000

Sets the time between pings being sent automatically. They measure the roundtrip time and keep connections from closing. Default: 1000.

For Photon's reliable UDP connections, pings are skipped if any reliable command was sent during the specified TimePingInterval. Any reliable command is used to update the RoundTripTime and RoundTripTimeVariance.

When using TCP and WebSockets, the ping is of interest to measure the roundtrip and to keep a connection open, should nothing else With those two protocols, the ping is used to update the RoundTripTime and RoundTripTimeVariance.

◆ TrafficRecorder

ITrafficRecorder ExitGames.Client.Photon.PhotonPeer.TrafficRecorder

If set, the TrafficRecorder will be used to capture all traffic.

If null or not Enabled, the recorder is not being used. Release builds of this library will never record traffic for performance reasons.

See ITrafficRecorder docs.

◆ WarningSize

int ExitGames.Client.Photon.PhotonPeer.WarningSize

The WarningSize was used test all message queues for congestion.

Property Documentation

◆ ByteArraySlicePool

ByteArraySlicePool ExitGames.Client.Photon.PhotonPeer.ByteArraySlicePool
get

Instance of a ByteArraySlicePool. UseByteArraySlicePoolForEvents defines if this PhotonPeer is using the pool for deserialization of byte[] in Photon events.

ByteArraySlice is a serializable datatype of the Photon .Net client library. It helps avoid allocations by being pooled and (optionally) used in incoming Photon events (see: UseByteArraySlicePoolForEvents).

You can also use the pool to acquire ByteArraySlice instances for serialization. RaiseEvent will auto-release all ByteArraySlice instances passed in.

◆ ByteCountCurrentDispatch

int ExitGames.Client.Photon.PhotonPeer.ByteCountCurrentDispatch
get

Gets the size of the dispatched event or operation-result in bytes. This value is set before OnEvent() or OnOperationResponse() is called (within DispatchIncomingCommands()).

Get this value directly in OnEvent() or OnOperationResponse(). Example: void OnEvent(...) { int eventSizeInBytes = this.peer.ByteCountCurrentDispatch; //...

void OnOperationResponse(...) { int resultSizeInBytes = this.peer.ByteCountCurrentDispatch; //...

◆ ByteCountLastOperation

int ExitGames.Client.Photon.PhotonPeer.ByteCountLastOperation
get

Gets the size of the last serialized operation call in bytes. The value includes all headers for this single operation but excludes those of UDP, Enet Package Headers and TCP.

Get this value immediately after calling an operation. Example:

this.loadbalancingClient.OpJoinRoom("myroom"); int opjoinByteCount = this.loadbalancingClient.ByteCountLastOperation;

◆ BytesIn

long ExitGames.Client.Photon.PhotonPeer.BytesIn
get

Gets count of all bytes coming in (including headers, excluding UDP/TCP overhead)

◆ BytesOut

long ExitGames.Client.Photon.PhotonPeer.BytesOut
get

Gets count of all bytes going out (including headers, excluding UDP/TCP overhead)

◆ ClientVersion

string ExitGames.Client.Photon.PhotonPeer.ClientVersion
get

Version of this library as string.

◆ CommandBufferSize

int ExitGames.Client.Photon.PhotonPeer.CommandBufferSize
getset

No effect anymore. Removed without replacement.

This value was used to get/set the initial capacities of command-lists. These grow on demand but knowing their capacity is of very limited use. Also, various command-lists grow their capacity independent from one another.

◆ CommandInfoCurrentDispatch

string? ExitGames.Client.Photon.PhotonPeer.CommandInfoCurrentDispatch
get

Returns the debug string of the event or operation-response currently being dispatched or string. Empty if none.

In a release build of the lib, this will always be empty.

◆ ConnectionTime

int ExitGames.Client.Photon.PhotonPeer.ConnectionTime
get

The internally used "per connection" time value, which is updated infrequently, when the library executes some connectio-related tasks.

This integer value is an infrequently updated value by design. The lib internally sets the value when it sends outgoing commands or reads incoming packages. This is based on SupportClass.GetTickCount() and an initial time value per (server) connection. This value is also used in low level Enet commands as sent time and optional logging.

◆ CountDiscarded

int ExitGames.Client.Photon.PhotonPeer.CountDiscarded
getset

Count of unreliable commands being discarded in case this client already dispatched a command that was newer (higher sequence number).

◆ CrcEnabled

bool ExitGames.Client.Photon.PhotonPeer.CrcEnabled
getset

While not connected, this controls if the next connection(s) should use a per-package CRC checksum.

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 cecks are counted in PhotonPeer.PacketLossByCrc.

◆ DeltaUnreliableNumber

int ExitGames.Client.Photon.PhotonPeer.DeltaUnreliableNumber
getset

Set per dispatch in DispatchIncomingCommands to: commandUnreliableSequenceNumber - channel.incomingUnreliableSequenceNumber. Indicates how big the (sequence)gap is, compared to the last dispatched unreliable command.

◆ DisconnectTimeout

int ExitGames.Client.Photon.PhotonPeer.DisconnectTimeout
getset

Time in milliseconds before any sent reliable command triggers a timeout disconnect, unless acknowledged by the receiver. Default: 10000.

DisconnectTimeout is not an exact value for a timeout. The exact timing of the timeout depends on the frequency of Service() calls and the roundtrip time. Commands sent with long roundtrip-times and variance are checked less often for re-sending.

DisconnectTimeout and SentCountAllowance are competing settings: either might trigger a disconnect on the client first, depending on the values and Roundtrip Time.

Default: 10000 ms. Maximum setting: 65535. Setting a negative value will apply the default timeout.

◆ EnableServerTracing

bool ExitGames.Client.Photon.PhotonPeer.EnableServerTracing
getset

Debugging option to tell the Photon Server to log all datagrams.

◆ EncryptorType

Type ExitGames.Client.Photon.PhotonPeer.EncryptorType
getset

Setter for the Datagram Encryptor instance. Used at next connect.

If null, the PhotonPeer will create a default encryptor instance, which may be native or managed. See also: PhotonPeer.NativeDatagramEncryptionLibAvailable.

◆ IsEncryptionAvailable

bool ExitGames.Client.Photon.PhotonPeer.IsEncryptionAvailable
get

This property is set internally, when OpExchangeKeysForEncryption successfully finished. While it's true, encryption can be used for operations.

◆ IsSendingOnlyAcks

bool ExitGames.Client.Photon.PhotonPeer.IsSendingOnlyAcks
getset

While true, the peer will not send any other commands except ACKs (used in UDP connections).

◆ IsSimulationEnabled

virtual bool ExitGames.Client.Photon.PhotonPeer.IsSimulationEnabled
getset

Gets or sets the network simulation "enabled" setting. Changing this value also locks this peer's sending and when setting false, the internally used queues are executed (so setting to false can take some cycles).

◆ LastRoundTripTime

int ExitGames.Client.Photon.PhotonPeer.LastRoundTripTime
get

The last measured roundtrip time for this connection.

◆ LastSendAckTime

int ExitGames.Client.Photon.PhotonPeer.LastSendAckTime
get

The last ConnectionTime value, when some ACKs were sent out by this client.

Only applicable to UDP connections.

◆ LastSendOutgoingTime

int ExitGames.Client.Photon.PhotonPeer.LastSendOutgoingTime
get

The last ConnectionTime value, when SendOutgoingCommands actually checked outgoing queues to send them. Must be connected.

Available for UDP and TCP connections.

◆ LimitOfUnreliableCommands

int ExitGames.Client.Photon.PhotonPeer.LimitOfUnreliableCommands
getset

No effect anymore. Removed without replacement.

This was used to skip some received (and buffered) unreliable commands, to avoid situations where the peer has aggregated a lot of (old) messages.

◆ Listener

IPhotonPeerListener ExitGames.Client.Photon.PhotonPeer.Listener
getprotected set

Gets the IPhotonPeerListener of this instance (set in constructor). Can be used in derived classes for Listener.DebugReturn().

◆ LocalMsTimestampDelegate

SupportClass.IntegerMillisecondsDelegate ExitGames.Client.Photon.PhotonPeer.LocalMsTimestampDelegate
set

This setter for the (local-) timestamp delegate replaces the default Environment.TickCount with any equal function.

About Environment.TickCount: The value of this property is derived from the system timer and is stored as a 32-bit signed integer. Consequently, if the system runs continuously, TickCount will increment from zero to Int32..::.MaxValue for approximately 24.9 days, then jump to Int32..::.MinValue, which is a negative number, then increment back to zero during the next 24.9 days.

Exceptions
ExceptionException is thrown peer.PeerState is not PS_DISCONNECTED.

◆ LocalTimeInMilliSeconds

int ExitGames.Client.Photon.PhotonPeer.LocalTimeInMilliSeconds
get

Gets a local timestamp in milliseconds by calling SupportClass.GetTickCount(). See LocalMsTimestampDelegate.

◆ LongestSentCall

int ExitGames.Client.Photon.PhotonPeer.LongestSentCall
getset

Measures the maximum milliseconds spent in PhotonSocket.Send().

◆ MaximumTransferUnit

int ExitGames.Client.Photon.PhotonPeer.MaximumTransferUnit
getset

The Maximum Trasfer Unit (MTU) defines the (network-level) packet-content size that is guaranteed to arrive at the server in one piece. The Photon Protocol uses this size to split larger data into packets and for receive-buffers of packets.

This value affects the Packet-content. The resulting UDP packages will have additional headers that also count against the package size (so it's bigger than this limit in the end) Setting this value while being connected is not allowed and will throw an Exception. Minimum is 576. Huge values won't speed up connections in most cases!

◆ NativeDatagramEncryptionLibAvailable

bool ExitGames.Client.Photon.PhotonPeer.NativeDatagramEncryptionLibAvailable
staticget

Checks if a native library for Datagram Encryption is available. To use it, see remarks.

If the PhotonPeer.EncryptorType is set, this type is used as implementation for Datagram Encryption. If it's not set, a native plugin is used if available. As fallback, a managed implementation is being used.

Note: The native plugin is performing much better than the managed alternatives. This is why we make the plugin available for various platforms.

Note: Native libraries must match the execution platform. Even if the native plugin is found it may fail to execute.

◆ NativePayloadEncryptionLibAvailable

bool ExitGames.Client.Photon.PhotonPeer.NativePayloadEncryptionLibAvailable
staticget

Checks if native library for Payload Encryption (PhotonCryptoPlugin.dll) is available. Used automatically.

While the encryptor Type for Datagram Encryption can be defined, Payload Encryption will always use built-in types as encryptor.

Note: Native libraries must match the execution platform. Even if the native plugin is found it may fail to execute.

◆ NativeSocketLibAvailable

bool ExitGames.Client.Photon.PhotonPeer.NativeSocketLibAvailable
staticget

Checks if a native library for network sockets (PhotonSocketPlugin.dll) is available. To use it, see remarks.

When the native socket library is available, the SocketNative class may be used as socket implementation.

If the SocketImplementationConfig is null, the SocketNative class is assigned for UDP, TCP and WebSocket.

Alternatively the type SocketNative (or other) can be assigend in the SocketImplementationConfig.

The SocketNative class in this assembly is compiled for dynamic linking. A class "SocketNativeSource" can be made available for you to compile it along with your source for platforms that use static linking (e.g. for iOS and some consoles).

Note: Native libraries must match the execution platform. Even if the native plugin is found it may fail to execute.

◆ NetworkSimulationSettings

NetworkSimulationSet ExitGames.Client.Photon.PhotonPeer.NetworkSimulationSettings
get

Gets the settings for built-in Network Simulation for this peer instance while IsSimulationEnabled will enable or disable them. Once obtained, the settings can be modified by changing the properties.

◆ PacketLossByChallenge

int ExitGames.Client.Photon.PhotonPeer.PacketLossByChallenge
get

Count of packages dropped due to wrong challenge for this connection.

◆ PacketLossByCrc

int ExitGames.Client.Photon.PhotonPeer.PacketLossByCrc
get

Count of packages dropped due to failed CRC checks for this connection.

CrcEnabled

◆ PeerID

string ExitGames.Client.Photon.PhotonPeer.PeerID
get

This peer's ID as assigned by the server or 0 if not using UDP. Will be 0xFFFF before the client connects.

Used for debugging only. This value is not useful in everyday Photon usage.

◆ PeerState

PeerStateValue ExitGames.Client.Photon.PhotonPeer.PeerState
get

This is the (low level) state of the connection to the server of a PhotonPeer. Managed internally and read-only.

Don't mix this up with the StatusCode provided in IPhotonListener.OnStatusChanged(). Applications should use the StatusCode of OnStatusChanged() to track their state, as it also covers the higher level initialization between a client and Photon.

◆ QueuedIncomingCommands

int ExitGames.Client.Photon.PhotonPeer.QueuedIncomingCommands
get

Count of all currently received but not-yet-Dispatched reliable commands (events and operation results) from all channels.

◆ QueuedOutgoingCommands

int ExitGames.Client.Photon.PhotonPeer.QueuedOutgoingCommands
get

Count of all commands currently queued as outgoing, including all channels and reliable, unreliable.

◆ QuickResendAttempts

byte ExitGames.Client.Photon.PhotonPeer.QuickResendAttempts
getset

Up to 4 resend attempts for a reliable command can be done in quick succession (after RTT+4*Variance).

By default 0. Any later resend attempt will then double the time before the next resend. Max value = 4; Make sure to adjust SentCountAllowance to a slightly higher value, as more repeats will get done.

◆ ResentReliableCommands

int? ExitGames.Client.Photon.PhotonPeer.ResentReliableCommands
get

Count of commands that got repeated (due to local repeat-timing before an ACK was received).

◆ ReuseEventInstance

bool ExitGames.Client.Photon.PhotonPeer.ReuseEventInstance
getset

Option to make the PhotonPeer reuse a single EventData instance for all incoming events.

This reduces memory garbage. If enabled, the event provided via OnEvent(EventData photonEvent) is invalid once the callback finished. That event's content will get modified. Typically this is not a problem as events are rarely cached.

Changing this value acquires the same lock that DispatchIncomingCommands() uses.

◆ RoundTripTime

int ExitGames.Client.Photon.PhotonPeer.RoundTripTime
get

Time until a reliable command is acknowledged by the server.

The value measures network latency and for UDP it includes the server's ACK-delay (setting in config). In TCP, there is no ACK-delay, so the value is slightly lower (if you use default settings for Photon).

RoundTripTime is updated constantly. Every reliable command will contribute a fraction to this value.

This is also the approximate time until a raised event reaches another client or until an operation result is available.

◆ RoundTripTimeVariance

int ExitGames.Client.Photon.PhotonPeer.RoundTripTimeVariance
get

Changes of the roundtriptime as variance value. Gives a hint about how much the time is changing.

◆ SentReliableCommandsCount

int ExitGames.Client.Photon.PhotonPeer.SentReliableCommandsCount
get

Gets the count of sent but not yet acknowledged commands (for UDP connections).

◆ SerializationProtocolType

SerializationProtocol ExitGames.Client.Photon.PhotonPeer.SerializationProtocolType
getset

Enables selection of a (Photon-)serialization protocol. Used in Connect methods.

Defaults to SerializationProtocol.GpBinaryV16;

◆ ServerAddress

string ExitGames.Client.Photon.PhotonPeer.ServerAddress
get

The server address which was used in PhotonPeer.Connect() or null (before Connect() was called).

◆ ServerIpAddress

string ExitGames.Client.Photon.PhotonPeer.ServerIpAddress
get

Contains the IP address of the previously resolved ServerAddress (or empty, if address wasn't resolved with the internal methods).

◆ ServerTimeInMilliSeconds

int? ExitGames.Client.Photon.PhotonPeer.ServerTimeInMilliSeconds
get

Approximated Environment.TickCount value of server (while connected).

UDP: The server's timestamp is automatically fetched after connecting (once). This is done internally by a command which is acknowledged immediately by the server. TCP: The server's timestamp fetched with each ping but set only after connecting (once).

The approximation will be off by +/- 10ms in most cases. Per peer/client and connection, the offset will be constant (unless FetchServerTimestamp() is used). A constant offset should be better to adjust for. Unfortunately there is no way to find out how much the local value differs from the original.

The approximation adds RoundtripTime / 2 and uses this.LocalTimeInMilliSeconds to calculate in-between values (this property returns a new value per tick).

The value sent by Photon equals Environment.TickCount in the logic layer.

0 until connected. While connected, the value is an approximation of the server's current timestamp.

◆ SocketImplementation

Type ExitGames.Client.Photon.PhotonPeer.SocketImplementation
getset

Can be used to read the IPhotonSocket implementation at runtime (before connecting).

Use the SocketImplementationConfig to define which IPhotonSocket is used per ConnectionProtocol.

◆ TimestampOfLastSocketReceive

int ExitGames.Client.Photon.PhotonPeer.TimestampOfLastSocketReceive
get

Timestamp of the last time anything (!) was received from the server (including low level Ping, ACKs, events and operation-returns).

This is not the time when something was dispatched. If you enable NetworkSimulation, this value is affected as well.

◆ TrafficStatsElapsedMs

long? ExitGames.Client.Photon.PhotonPeer.TrafficStatsElapsedMs
get

Returns the count of milliseconds the stats are enabled for tracking.

◆ TrafficStatsEnabled

bool ExitGames.Client.Photon.PhotonPeer.TrafficStatsEnabled
getset

Enables or disables collection of statistics in TrafficStatsIncoming, TrafficStatsOutgoing and TrafficstatsGameLevel.

Setting this to true, also starts the stopwatch to measure the timespan the stats are collected. Enables the traffic statistics of a peer: TrafficStatsIncoming, TrafficStatsOutgoing and TrafficstatsGameLevel (nothing else). Default value: false (disabled).

◆ TrafficStatsGameLevel

TrafficStatsGameLevel ExitGames.Client.Photon.PhotonPeer.TrafficStatsGameLevel
getset

Gets a statistic of incoming and outgoing traffic, split by operation, operation-result and event.

Operations are outgoing traffic, results and events are incoming. Includes the per-command header sizes (Udp: Enet Command Header or Tcp: Message Header).

◆ TrafficStatsIncoming

TrafficStats ExitGames.Client.Photon.PhotonPeer.TrafficStatsIncoming
getset

Gets the byte-count of incoming "low level" messages, which are either Enet Commands or Tcp Messages. These include all headers, except those of the underlying internet protocol Udp or Tcp.

◆ TrafficStatsOutgoing

TrafficStats ExitGames.Client.Photon.PhotonPeer.TrafficStatsOutgoing
getset

Gets the byte-count of outgoing "low level" messages, which are either Enet Commands or Tcp Messages. These include all headers, except those of the underlying internet protocol Udp or Tcp.

◆ TransportProtocol

ConnectionProtocol ExitGames.Client.Photon.PhotonPeer.TransportProtocol
getset

This is the transport protocol to be used for next connect (see remarks).

The TransportProtocol can be changed anytime but it will not change the currently active connection. Instead, TransportProtocol will be applied on next Connect.

◆ UseByteArraySlicePoolForEvents

bool ExitGames.Client.Photon.PhotonPeer.UseByteArraySlicePoolForEvents
getset

Enables a deserialization optimization for incoming events. Defaults to false.

When enabled, byte-arrays in incoming Photon events are deserialized into pooled ByteArraySlice instances (wrappers for byte[]). This improves the memory footprint for receiving byte-arrays in events.

When used, you have to release the (pooled) ByteArraySlice instances.

Adjust your handling of EventData accordingly:

The ByteArraySlice.Buffer will usually be bigger than the send/received byte-array. Check the ByteArraySlice.Count and read only the actually received bytes. The Buffer is reused and not cleared. The Offset will be 0 for incoming events.

Important: While the peer will acquire the ByteArraySlice and passes it to OnEvent, the game code has to call ByteArraySlice.Release() when the slice is no longer needed.

Send either byte[], ArraySegment or use the ByteArraySlicePool to acquire ByteArraySlices to send.

◆ UsedProtocol

ConnectionProtocol ExitGames.Client.Photon.PhotonPeer.UsedProtocol
get

The protocol this peer is currently connected/connecting with (or 0).

◆ WrapIncomingStructs

bool ExitGames.Client.Photon.PhotonPeer.WrapIncomingStructs
getset

Incoming struct types are wrapped in a pooled IWrapperStruct, rather than being cast to object. This eliminated allocations and garbage collection from boxing, however object that are wrapped structs will need to be cast to WrapperStruct<T> and their values extracted with (obj as WrapperStruct<T>).Value.

Event Documentation

◆ OnDisconnectMessage

Action<DisconnectMessage> ExitGames.Client.Photon.PhotonPeer.OnDisconnectMessage

Called when the client received a Disconnect Message from the server. Signals an error and provides a message to debug the case.


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