Photon .NET Client API
Public Member Functions | Static Public Member Functions | Public Attributes | Properties | 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:
ExitGames.Client.Photon.LoadBalancing.LoadBalancingPeer

Public Member Functions

void TrafficStatsReset ()
 Creates new instances of TrafficStats and starts a new timer for those. More...
 
string CommandLogToString ()
 Converts the CommandLog into a readable table-like string with summary. More...
 
 PhotonPeer (ConnectionProtocol protocolType)
 
 PhotonPeer (IPhotonPeerListener listener, ConnectionProtocol protocolType)
 Creates a new PhotonPeer instance to communicate with Photon and selects either UDP or TCP as protocol. We recommend UDP. More...
 
 PhotonPeer (IPhotonPeerListener listener)
 Creates a new PhotonPeer instance to communicate with Photon. More...
 
 PhotonPeer (IPhotonPeerListener listener, bool useTcp)
 Deprecated. Please use: PhotonPeer(IPhotonPeerListener listener, ConnectionProtocol protocolType). More...
 
virtual bool Connect (String serverAddress, String applicationName)
 This method does a DNS lookup (if necessary) and connects to the given serverAddress. 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...
 
virtual void Service ()
 This method excutes DispatchIncomingCommands and SendOutgoingCommands in your application Thread-context. More...
 
virtual bool SendOutgoingCommands ()
 This method creates a UDP/TCP package for outgoing commands (operations and acknowledgements) and sends them to the server. This method is also called by Service(). More...
 
virtual bool SendAcksOnly ()
 
virtual bool DispatchIncomingCommands ()
 This method directly causes the 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. 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...
 
virtual bool OpCustom (byte customOpCode, Dictionary< byte, object > customOpParameters, bool sendReliable)
 Channel-less wrapper for OpCustom(). More...
 
virtual bool OpCustom (byte customOpCode, Dictionary< byte, object > customOpParameters, bool sendReliable, byte channelId)
 Allows the client to send any operation to the Photon Server by setting any opCode and the operation's parameters. More...
 
virtual bool OpCustom (byte customOpCode, Dictionary< byte, object > customOpParameters, bool sendReliable, byte channelId, bool encrypt)
 Allows the client to send any operation to the Photon Server by setting any opCode and the operation's parameters. More...
 
virtual bool OpCustom (OperationRequest operationRequest, bool sendReliable, byte channelId, bool encrypt)
 Allows the client to send any operation to the Photon Server by setting any opCode and the operation's parameters. More...
 

Static Public Member Functions

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

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...
 

Properties

Type SocketImplementation [get, set]
 Can be used to set a UDP IPhotonSocket implementation at runtime (before connecting) in compatible DLL builds. More...
 
DebugLevel DebugOut [get, set]
 Sets the level (and amount) of debug output provided by the library. More...
 
IPhotonPeerListener Listener [get, set]
 Gets the IPhotonPeerListener of this instance (set in constructor). Can be used in derived classes for Listener.DebugReturn(). 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 TrafficStatsEnabled [get, set]
 Enables the traffic statistics of a peer: TrafficStatsIncoming, TrafficStatsOutgoing and TrafficstatsGameLevel (nothing else). Default value: false (disabled). More...
 
long TrafficStatsElapsedMs [get]
 Returns the count of milliseconds the stats are enabled for tracking. More...
 
TrafficStats TrafficStatsIncoming [get]
 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]
 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]
 Gets a statistic of incoming and outgoing traffic, split by operation, operation-result and event. More...
 
int CommandLogSize [get, set]
 Size of CommandLog. Default is 0, no logging. 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 CommandBufferSize [get]
 Initial size internal lists for incoming/outgoing commands (reliable and unreliable). More...
 
int RhttpMinConnections [get, set]
 (default=2) minimum number of open connections More...
 
int RhttpMaxConnections [get, set]
 (default=6) maximum number of open connections, should be > RhttpMinConnections More...
 
int LimitOfUnreliableCommands [get, set]
 Limits the queue of received unreliable commands within DispatchIncomingCommands before dispatching them. This works only in UDP. This limit is applied when you call DispatchIncomingCommands. If this client (already) received more than LimitOfUnreliableCommands, it will throw away the older ones instead of dispatching them. This can produce bigger gaps for unreliable commands but your client catches up faster. 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...
 
byte ChannelCount [get, set]
 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 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 ResentReliableCommands [get]
 Count of commands that got repeated (due to local repeat-timing before an ACK was received). More...
 
int WarningSize [get, set]
 The WarningSize is used test all message queues for congestion (in and out, reliable and unreliable). OnStatusChanged will be called with a warning if a queue holds WarningSize commands or a multiple of it. Default: 100. Example: If command is received, OnStatusChanged will be called when the respective command queue has 100, 200, 300 ... items. More...
 
int SentCountAllowance [get, set]
 Number of send retries before a peer is considered lost/disconnected. Default: 5. 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. More...
 
int TimePingInterval [get, set]
 Sets the milliseconds without reliable command before a ping command (reliable) will be sent (Default: 1000ms). The ping command is used to keep track of the connection in case the client does not send reliable commands by itself. A ping (or reliable commands) will update the RoundTripTime calculation. More...
 
int DisconnectTimeout [get, set]
 Milliseconds after which a reliable UDP command triggers a timeout disconnect, unless acknowledged by server. This value currently only affects UDP connections. DisconnectTimeout is not an exact value for a timeout. The exact timing of the timeout depends on the frequency of Service() calls and commands that are sent with long roundtrip-times and variance are checked less often for re-sending! More...
 
int ServerTimeInMilliSeconds [get]
 Approximated Environment.TickCount value of server (while connected). 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 LocalTimeInMilliSeconds [get]
 Gets a local timestamp in milliseconds by calling SupportClass.GetTickCount(). See LocalMsTimestampDelegate. More...
 
SupportClass.IntegerMillisecondsDelegate LocalMsTimestampDelegate [set]
 This setter for the (local-) timestamp delegate replaces the default Environment.TickCount with any equal function. 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 TimestampOfLastSocketReceive [get]
 Stores timestamp of the last time anything (!) was received from the server (including low level Ping and ACKs but also events and operation-returns). This is not the time when something was dispatched. If you enable NetworkSimulation, this value is affected as well. More...
 
string ServerAddress [get, set]
 The server address which was used in PhotonPeer.Connect() or null (before Connect() was called). More...
 
ConnectionProtocol UsedProtocol [get]
 The protocol this Peer uses to connect to Photon. 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...
 
static int OutgoingStreamBufferSize [get, set]
 Defines the initial size of an internally used MemoryStream for Tcp. The MemoryStream is used to aggregate operation into (less) send calls, which uses less resoures. 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...
 

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

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

Creates a new PhotonPeer instance to communicate with Photon and selects either UDP or TCP as protocol. We recommend UDP.

Parameters
listenera IPhotonPeerListener implementation
protocolTypeProtocol to use to connect to Photon.
ExitGames.Client.Photon.PhotonPeer.PhotonPeer ( IPhotonPeerListener  listener)
inline

Creates a new PhotonPeer instance to communicate with Photon.

Connection is UDP based, except for Silverlight.

Parameters
listenera IPhotonPeerListener implementation
ExitGames.Client.Photon.PhotonPeer.PhotonPeer ( IPhotonPeerListener  listener,
bool  useTcp 
)
inline

Member Function Documentation

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

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

Sent reliable commands begin with SND. Their acknowledgements with ACK. ACKs list the reliable sequence number of the command they acknowledge (not their own). Careful: This method should not be called frequently, as it's time- and memory-consuming to create the log.

virtual bool ExitGames.Client.Photon.PhotonPeer.Connect ( String  serverAddress,
String  applicationName 
)
inlinevirtual

This method does a DNS lookup (if necessary) and connects to the given serverAddress.

The return value gives you feedback if the address has the correct format. If so, this starts the process to establish the connection itself, which might take a few seconds.

When the connection is established, a callback to IPhotonPeerListener.OnStatusChanged will be done. If the connection can't be established, despite having a valid address, the OnStatusChanged is called with an error-value.

The applicationName defines the application logic to use server-side and it should match the name of one of the apps in your server's config.

By default, the applicationName is "LoadBalancing" but there is also the "MmoDemo". You can setup your own application and name it any way you like.

Parameters
serverAddressAddress of the Photon server. Format: ip:port (e.g. 127.0.0.1:5055) or hostname:port (e.g. localhost:5055)
applicationNameThe name of the application to use within Photon or the appId of PhotonCloud. Should match a "Name" for an application, as setup in your PhotonServer.config.
Returns
true if IP is available (DNS name is resolved) and server is being connected. false on error.
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 (EventCode.Leave) for the remaining players.

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

This method directly causes the 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.

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
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.

virtual bool ExitGames.Client.Photon.PhotonPeer.OpCustom ( byte  customOpCode,
Dictionary< byte, object >  customOpParameters,
bool  sendReliable 
)
inlinevirtual

Channel-less wrapper for OpCustom().

Parameters
customOpCodeOperations are handled by their byte-typed code. The codes of the "LoadBalancong" application are in the class ExitGames.Client.Photon.LoadBalancing.OperationCode.
customOpParametersContaining parameters as key-value pair. The key is byte-typed, while the value is any serializable datatype.
sendReliableSelects if the operation must be acknowledged or not. If false, the operation is not guaranteed to reach the server.
Returns
If operation could be enqueued for sending
virtual bool ExitGames.Client.Photon.PhotonPeer.OpCustom ( byte  customOpCode,
Dictionary< byte, object >  customOpParameters,
bool  sendReliable,
byte  channelId 
)
inlinevirtual

Allows the client to send any operation to the Photon Server by setting any opCode and the operation's parameters.

Photon can be extended with new operations which are identified by a single byte, defined server side and known as operation code (opCode). Similarly, the operation's parameters are defined server side as byte keys of values, which a client sends as customOpParameters accordingly.

This is explained in more detail as "Operations".

Parameters
customOpCodeOperations are handled by their byte-typed code. The codes of the "LoadBalancing" application are in the class ExitGames.Client.Photon.LoadBalancing.OperationCode.
customOpParametersContaining parameters as key-value pair. The key is byte-typed, while the value is any serializable datatype.
sendReliableSelects if the operation must be acknowledged or not. If false, the operation is not guaranteed to reach the server.
channelIdThe channel in which this operation should be sent.
Returns
If operation could be enqueued for sending
virtual bool ExitGames.Client.Photon.PhotonPeer.OpCustom ( byte  customOpCode,
Dictionary< byte, object >  customOpParameters,
bool  sendReliable,
byte  channelId,
bool  encrypt 
)
inlinevirtual

Allows the client to send any operation to the Photon Server by setting any opCode and the operation's parameters.

Variant with encryption parameter.

Use this only after encryption was established by EstablishEncryption and waiting for the OnStateChanged callback.

Parameters
customOpCodeOperations are handled by their byte-typed code. The codes of the "LoadBalancing" application are in the class ExitGames.Client.Photon.LoadBalancing.OperationCode.
customOpParametersContaining parameters as key-value pair. The key is byte-typed, while the value is any serializable datatype.
sendReliableSelects if the operation must be acknowledged or not. If false, the operation is not guaranteed to reach the server.
channelIdThe channel in which this operation should be sent.
encryptCan only be true, while IsEncryptionAvailable is true, too.
Returns
If operation could be enqueued for sending
virtual bool ExitGames.Client.Photon.PhotonPeer.OpCustom ( OperationRequest  operationRequest,
bool  sendReliable,
byte  channelId,
bool  encrypt 
)
inlinevirtual

Allows the client to send any operation to the Photon Server by setting any opCode and the operation's parameters.

Variant with an OperationRequest object.

This variant offers an alternative way to describe a operation request. Operation code and it's parameters are wrapped up in a object. Still, the parameters are a Dictionary.

Parameters
operationRequestThe operation to call on Photon.
sendReliableUse unreliable (false) if the call might get lost (when it's content is soon outdated).
channelIdDefines the sequence of requests this operation belongs to.
encryptEncrypt request before sending. Depends on IsEncryptionAvailable.
Returns
If operation could be enqueued for sending
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.
static bool ExitGames.Client.Photon.PhotonPeer.RegisterType ( Type  customType,
byte  code,
SerializeStreamMethod  serializeMethod,
DeserializeStreamMethod  constructor 
)
inlinestatic
virtual bool ExitGames.Client.Photon.PhotonPeer.SendAcksOnly ( )
inlinevirtual
virtual bool ExitGames.Client.Photon.PhotonPeer.SendOutgoingCommands ( )
inlinevirtual

This method creates a UDP/TCP package for outgoing commands (operations and acknowledgements) and sends them to the server. This method is 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.
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
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.

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

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

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

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

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

Property Documentation

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; //...

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;

long ExitGames.Client.Photon.PhotonPeer.BytesIn
get

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

long ExitGames.Client.Photon.PhotonPeer.BytesOut
get

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

byte ExitGames.Client.Photon.PhotonPeer.ChannelCount
getset

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.

int ExitGames.Client.Photon.PhotonPeer.CommandBufferSize
get

Initial size internal lists for incoming/outgoing commands (reliable and unreliable).

This sets only the initial size. All lists simply grow in size as needed. This means that incoming or outgoing commands can pile up and consume heap size if Service is not called often enough to handle the messages in either direction.

Configure the WarningSize, to get callbacks when the lists reach a certain size.

UDP: Incoming and outgoing commands each have separate buffers for reliable and unreliable sending. There are additional buffers for "sent commands" and "ACKs". TCP: Only two buffers exist: incoming and outgoing commands.

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.

int ExitGames.Client.Photon.PhotonPeer.CommandLogSize
getset

Size of CommandLog. Default is 0, no logging.

A bigger log is better for debugging but uses more memory. Get the log as string via CommandLogToString.

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.

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.

DebugLevel ExitGames.Client.Photon.PhotonPeer.DebugOut
getset

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

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

int ExitGames.Client.Photon.PhotonPeer.DisconnectTimeout
getset

Milliseconds after which a reliable UDP command triggers a timeout disconnect, unless acknowledged by server. This value currently only affects UDP connections. DisconnectTimeout is not an exact value for a timeout. The exact timing of the timeout depends on the frequency of Service() calls and commands that are 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 Rountrip Time. Default: 10000 ms.

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.

bool ExitGames.Client.Photon.PhotonPeer.IsSendingOnlyAcks
getset

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

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).

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.

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.

int ExitGames.Client.Photon.PhotonPeer.LimitOfUnreliableCommands
getset

Limits the queue of received unreliable commands within DispatchIncomingCommands before dispatching them. This works only in UDP. This limit is applied when you call DispatchIncomingCommands. If this client (already) received more than LimitOfUnreliableCommands, it will throw away the older ones instead of dispatching them. This can produce bigger gaps for unreliable commands but your client catches up faster.

This can be useful when the client couldn't dispatch anything for some time (cause it was in a room but loading a level). If set to 20, the incoming unreliable queues are truncated to 20. If 0, all received unreliable commands will be dispatched. This is a "per channel" value, so each channel can hold up to LimitOfUnreliableCommands commands. This value interacts with DispatchIncomingCommands: If that is called less often, more commands get skipped.

IPhotonPeerListener ExitGames.Client.Photon.PhotonPeer.Listener
getset

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

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.
int ExitGames.Client.Photon.PhotonPeer.LocalTimeInMilliSeconds
get

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

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!

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.

int ExitGames.Client.Photon.PhotonPeer.OutgoingStreamBufferSize
staticgetset

Defines the initial size of an internally used MemoryStream for Tcp. The MemoryStream 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 poutgoing data is actually sent.

int ExitGames.Client.Photon.PhotonPeer.PacketLossByChallenge
get

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

int ExitGames.Client.Photon.PhotonPeer.PacketLossByCrc
get

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

CrcEnabled

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.

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.

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.

int ExitGames.Client.Photon.PhotonPeer.QueuedOutgoingCommands
get

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

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.

int ExitGames.Client.Photon.PhotonPeer.ResentReliableCommands
get

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

int ExitGames.Client.Photon.PhotonPeer.RhttpMaxConnections
getset

(default=6) maximum number of open connections, should be > RhttpMinConnections

int ExitGames.Client.Photon.PhotonPeer.RhttpMinConnections
getset

(default=2) minimum number of open connections

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.

int ExitGames.Client.Photon.PhotonPeer.RoundTripTimeVariance
get

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

int ExitGames.Client.Photon.PhotonPeer.SentCountAllowance
getset

Number of send retries before a peer is considered lost/disconnected. Default: 5. 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 Rountrip Time.

string ExitGames.Client.Photon.PhotonPeer.ServerAddress
getset

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

The ServerAddress can only be changed for HTTP connections (to replace one that goes through a Loadbalancer with a direct URL).

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.

Type ExitGames.Client.Photon.PhotonPeer.SocketImplementation
getset

Can be used to set a UDP IPhotonSocket implementation at runtime (before connecting) in compatible DLL builds.

This won't work for TCP and regular C# libraries. Get in contact with us.

int ExitGames.Client.Photon.PhotonPeer.TimePingInterval
getset

Sets the milliseconds without reliable command before a ping command (reliable) will be sent (Default: 1000ms). The ping command is used to keep track of the connection in case the client does not send reliable commands by itself. A ping (or reliable commands) will update the RoundTripTime calculation.

int ExitGames.Client.Photon.PhotonPeer.TimestampOfLastSocketReceive
get

Stores timestamp of the last time anything (!) was received from the server (including low level Ping and ACKs but also events and operation-returns). This is not the time when something was dispatched. If you enable NetworkSimulation, this value is affected as well.

long ExitGames.Client.Photon.PhotonPeer.TrafficStatsElapsedMs
get

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

bool ExitGames.Client.Photon.PhotonPeer.TrafficStatsEnabled
getset

Enables the traffic statistics of a peer: TrafficStatsIncoming, TrafficStatsOutgoing and TrafficstatsGameLevel (nothing else). Default value: false (disabled).

TrafficStatsGameLevel ExitGames.Client.Photon.PhotonPeer.TrafficStatsGameLevel
get

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).

TrafficStats ExitGames.Client.Photon.PhotonPeer.TrafficStatsIncoming
get

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.

TrafficStats ExitGames.Client.Photon.PhotonPeer.TrafficStatsOutgoing
get

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.

ConnectionProtocol ExitGames.Client.Photon.PhotonPeer.UsedProtocol
get

The protocol this Peer uses to connect to Photon.

int ExitGames.Client.Photon.PhotonPeer.WarningSize
getset

The WarningSize is used test all message queues for congestion (in and out, reliable and unreliable). OnStatusChanged will be called with a warning if a queue holds WarningSize commands or a multiple of it. Default: 100. Example: If command is received, OnStatusChanged will be called when the respective command queue has 100, 200, 300 ... items.


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