You are on page 1of 58

Photon DotNet Client

Documentation
for DotNet, Unity3D and Silverlight SDKs

Copyright (c) 2010. All rights reserved.

Photon DotNet Client Documentation

Table of Contents
Overview

Photon Workflow

Operations

Events

Fragmentation and Channels

Using TCP

Serializable Datatypes

The Photon Server

Lite Application

Properties on Photon
Further Help

DotNet Platforms

6
7

Photon for Unity3D

Photon for Silverlight

Symbol Reference
Classes

10
10

ArrayList Class
ArrayList Constructor

10
10

ArrayList.ArrayList Constructor ()

11

ArrayList.ArrayList Constructor (int)

11

ArrayList Fields
ArrayList.SyncRoot Field
ArrayList Methods
ArrayList.Synchronized Method
Hashtable Class
Hashtable Constructor

11
11
11
11
11
12

Hashtable.Hashtable Constructor ()

12

Hashtable.Hashtable Constructor (int)

12

Hashtable Methods

12

Hashtable.Synchronized Method

12

Hashtable.this Indexer

12

Hashtable.ToString Method

13
ii

Photon DotNet Client Documentation


LitePeer Class
LitePeer Constructor

13
16

LitePeer.LitePeer Constructor (IPhotonPeerListener)

16

LitePeer.LitePeer Constructor (IPhotonPeerListener, ConnectionProtocol)

17

LitePeer.LitePeer Constructor (IPhotonPeerListener, bool)

17

LitePeer Methods

17

LitePeer.OpGetProperties Method

17

OpGetPropertiesOfActor Method

17

OpGetPropertiesOfGame Method

18

OpJoin Method

19

OpLeave Method

20

OpRaiseEvent Method

20

LitePeer.OpSetPropertiesOfActor Method

22

LitePeer.OpSetPropertiesOfGame Method

22

PhotonPeer Class
PhotonPeer Constructor

23
26

PhotonPeer.PhotonPeer Constructor (IPhotonPeerListener)

26

PhotonPeer.PhotonPeer Constructor (IPhotonPeerListener, ConnectionProtocol)

26

PhotonPeer.PhotonPeer Constructor (IPhotonPeerListener, bool)

27

PhotonPeer Fields
PhotonPeer.PhotonPort Field
PhotonPeer Methods

27
27
27

PhotonPeer.Connect Method

27

PhotonPeer.DeriveSharedKey Method

28

PhotonPeer.Disconnect Method

28

PhotonPeer.DispatchIncomingCommands Method

28

PhotonPeer.FetchServerTimestamp Method

28

OpCustom Method

29

PhotonPeer.OpExchangeKeysForEncryption Method

30

PhotonPeer.SendOutgoingCommands Method

30

PhotonPeer.Service Method

31

PhotonPeer.StopThread Method

31

PhotonPeer Properties

31

PhotonPeer.BytesIn Property

31

PhotonPeer.BytesOut Property

32

PhotonPeer.ChannelCount Property

32

PhotonPeer.CommandBufferSize Property

32

PhotonPeer.DebugOut Property

32

PhotonPeer.debugTimeForDeriveSharedKey Property

32

PhotonPeer.debugTimeForDiffieHellman Property

32

PhotonPeer.DisconnectTimeout Property

33

PhotonPeer.IsEncryptionAvailable Property

33
iii

Photon DotNet Client Documentation


PhotonPeer.Listener Property

33

PhotonPeer.LocalMsTimestampDelegate Property

33

PhotonPeer.LocalTimeInMilliSeconds Property

33

PhotonPeer.PeerID Property

33

PhotonPeer.PeerState Property

34

PhotonPeer.QueuedIncomingCommands Property

34

PhotonPeer.QueuedOutgoingCommands Property

34

PhotonPeer.RoundTripTime Property

34

PhotonPeer.RoundTripTimeVariance Property

34

PhotonPeer.SentCountAllowance Property

34

PhotonPeer.ServerAddress Property

35

PhotonPeer.ServerTimeInMilliSeconds Property

35

PhotonPeer.TimePingInterval Property

35

PhotonPeer.UseCommandActionQueue Property

35

PhotonPeer.UsedProtocol Property

36

PhotonPeer.WarningSize Property

36

PhotonPeer Delegates
PhotonPeer.GetLocalMsTimestampDelegate Delegate
SupportClass Class
SupportClass Classes
SupportClass.ThreadSafeRandom Class
SupportClass Methods

36
36
36
37
37
37

SupportClass.ByteArrayToString Method

37

SupportClass.DeserializeData Method

37

SupportClass.HashtableToString Method

38

NumberToByteArray Method

38

SupportClass.SerializeData Method

39

SupportClass.WriteStackTrace Method

39

Interfaces

39

IPhotonPeerListener Interface
IPhotonPeerListener Methods

39
40

IPhotonPeerListener.DebugReturn Method

40

IPhotonPeerListener.EventAction Method

40

IPhotonPeerListener.OperationResult Method

41

IPhotonPeerListener.PeerStatusCallback Method

41

Structs, Records, Enums

42

ConnectionProtocol Enumeration

43

DebugLevel Enumeration

43

LiteEventCode Enumeration

43

LiteEventKey Enumeration

44

LiteOpCode Enumeration

45

iv

Photon DotNet Client Documentation


LiteOpKey Enumeration

45

LitePropertyTypes Enumeration

46

PeerStateValue Enumeration

47

PhotonEventKey Enumeration

47

PhotonOpParameterKey Enumeration

48

StatusCode Enumeration

48

Index

1.1 Photon Workflow

Photon DotNet Client Documentation

1 Overview
Photon is a development framework to build real-time multiplayer games and applications for various platforms. It consists of
a Server SDK and Client SDKs for several platforms.

1
This is the documentation and reference for the Photon Client Library for DotNet, including Unity and Silverlight. Additional
documentation and help is available online. Visit: developer.exitgames.com.com and forum.exitgames.com

Photon provides a low-latency communication-layer based on UDP (or alternatively TCP). This protocol allows reliable and
unreliable transfer of data in "commands". On top of this, an operation- and event-framework is established to ease
development of your own games. We developed several applications and included them in the server SDK as example and
code base.

Server-side, the "Lite" application offers the basic operations that we felt useful for most room-based multiplayer games. We
included it's operations and events ( see page 3) are part of of the client API. The MMO application focuses on seamless
worlds and it's client side api is available in source in the MMO application's code (as it shares code with the server side).

The following API is used on several platforms: DotNet for Windows, Mono but also Unity3D scripting and Silverlight.

1.1 Photon Workflow


To get an impression of how to work on the client, we will use the server's Lite logic. This application defines rooms which
are created when users try to join them. Each user in a room becomes an actor with her own number.

A simplified workflow looks like this:

create a LitePeer (

see page 13) instance

from now on: regularly call Service() (


second)
call Connect() (

see page 31) to get events (

see page 3) and send commands (e.g. ten times a

see page 27) to connect the server

wait until the library calls IPhotonPeerListener.PeerStatusCallback (


the returned status int should equal StatusCode.Connect (
call OpJoin() (

see page 41)

see page 48)

see page 19) to get into a game

wait until the library calls OperationResult() (

see page 41) with opCode: LiteOpCode.Join (

send data in the game by calling OpRaiseEvent() (

see page 45)

see page 20)

receive events ( see page 3) in IPhotonPeerListener.EventAction() (


OpRaiseEvent())

see page 40) of type "evCode" (you used some in

1.2 Operations

Photon DotNet Client Documentation

when you are done: call LitePeer.OpLeave (

see page 20) to quit/leave the game

wait for "leave" return in OperationResult() (


disconnect with Disconnect() (

see page 41) with opCode: LiteOpCode.Leave (

see page 45)

see page 28)

check "disconnect" return in PeerStatusCallback() (


page 48)

see page 41) with statusCode: StatusCode.Disconnect (

see

Combined with the server's Lite application, this simple workflow would allow you to use rooms and send your game's events
( see page 3). The methods used could be broken down into three layers:

1
Low Level: Service, Connect, Disconnect and the StatusCallback are directly referring to the connection to the server.
This level works with UDP/TCP packets which transport commands (which in turn carry your operations). It keeps your
connection alive and organizes your RPC calls and events ( see page 3) into packages.
Logic Level: Operations ( see page 2), results and events ( see page 3) make up the logical level in Photon. Any
operation defined on the server (think RPC call) and can have a result. Events ( see page 3) are incoming from the
server and update the client with some data.
Application Level: Made up by a specific application and its features. In this case we use the operations and logic of the
Lite application. In this specific case, we have rooms and actors and more. The LitePeer ( see page 13) is matching the
server side implementation and wraps it up for you.
You don't have to manage the low level communication in most cases. However, it makes sense to know that everything that
goes from client to server (and the other way round) is put into "commands". Internally, commands are also used to establish
and keep the connection between client and server alive (without carrying additional data).

All methods that are operations (RPC calls) are prefixed with "Op" to tell them apart from anything else. Other server side
applications (like MMO or your own) will define different operations. These will have different parameters and return values.
These operations are not part of the client library but can be implemented by calling OpCustom().

The interface IPhotonPeerListener (

see page 39) must be implemented for callbacks. They are:

PeerStatusCallback ( see page 41) is for peer state-changes (connect, disconnect, errors, compare with StatusCode
Enumeration ( see page 48))
OperationResult (
EventAction (

see page 41) is the callback for operations (join, leave, etc.)

see page 40) as callback for events (

DebugReturn (

see page 40) as callback to debug output (less frequently used by release builds)

The following properties in PhotonPeer (

TimePingInterval (
RoundTripTime (

see page 3) coming in

see page 23) are of special interest:

see page 35) sets the time between ping-operations


see page 34) of reliable operations to the server and back

RoundTripTimeVariance (
ServerTimeInMilliSeconds (

see page 34) shows the variability of the roundtrip time


see page 35) is the continuously approximated server's time

1.2 Operations
Operation is our term for remote procedure calls (RPC) on Photon. This in turn can be described as methods that are
implemented on the server-side and called by clients. As any method, they have parameters and return values. The Photon
development framework takes care of getting your RPC calls from clients to server and results back.
2

1.4 Fragmentation and Channels

Photon DotNet Client Documentation

Server-side, operations are part of an application running on top of Photon. The default application provided by Exit Games
is called "Lite Application" or simply Lite. The LitePeer ( see page 13) class extends the PhotonPeer ( see page 23) by
methods for each of the Lite Operations.
Examples for Lite Operations are "join" and "raise event". On the client side, they can be found in the LitePeer ( see page
13) class as methods: OpJoin and OpRaiseEvent. They can be used right away with the default implementation of Photon
and the Lite Application.

Custom Operations
Photon is extendable with features that are specific to your game. You could persist world states or double check information
from the clients. Any operation that is not in Lite or the MMO application logic is called Custom Operation. Creating those is
primarily a server-side task, of course, but the clients have to use new functions / operations of the server.
So Operations are methods that can be called from the client side. They can have any number of parameters and any name.
To preserve bandwidth, we assign byte-codes for every operation and each parameter. The definition is done server side.
Each Operation has its own, unique number to identify it, known as the operation code (opCode). An operation class defines
the expected parameters and assigns a parameter code for each. With this definition, the client side only has to fill in the
values and let the server know the opCode of the Operation.
Photon uses Hashtables to aggregate the opCode and all parameters. Use OpCustom() (
Hashtable ( see page 11) and call any operation.

see page 29) to send your

Client side, opCode and parameter-codes are currently of type byte (to minimize overhead). They need to match the
definition of the server side to successfully call your operation.

OpCodes: byte versus short


Currently, the server side uses the short-type to define opCodes and parameter keys while the client side uses bytes only.
This is a remainder of Neutron, essentially, where we implemented more values of opCodes. But using short for each
opCode and parameter is a lot of overhead in a realtime environment, so we decided to revert this in the protocol and just
send bytes. This simply save lots of bandwidth.
OpCodes and parameters are mapped by value, of course.

1.3 Events
Unlike operations, events are "messages" that are rarely triggered by the client that receives them. Events come from
outside: the server or other clients.
They are created as side effect of operations (e.g. when you join a room) or raised as main purpose of the operation Raise
Event. Most events carry some form of data but in rare cases the type of event itself is the message.
Events are (once more) Hashtables with arbitrary content.

1.4 Fragmentation and Channels


Fragmentation
Bigger data chunks of data (more than 1kB) are not fitting into a single package, so they are fragmented and reassembled
automatically. Depending on the data size, this takes up multiple packages.
3

1.5 Using TCP

Photon DotNet Client Documentation

Be aware that this might stall other commands. Call Service() or SendOutgoingCommands() more often than absolutely
necessary. You should check that PhotonPeer.QueuedOutgoingCommands ( see page 34) is becoming zero regularly to
make sure everything gets out. You can also check the debug output for "UDP package is full", which can happen from time
to time but should not happen permanently.

Sequencing
The sequencing of the protocol makes sure that any receiving client will Dispatch your actions in the order you sent them.
Unreliable data is considered replaceable and can be lost. Reliable events ( see page 3) and operations will be repeated
several times if needed but they will all be Dispatched in order without gaps. Unreliable actions are also related to the last
reliable action and not Dispatched before that reliable data was Dispatched first. This can be useful, if the events ( see
page 3) are related to each other.
Example: Your FPS sends out unreliable movement updates and reliable chat messages. A lost package with movement
updates would be left out as the next movement update is coming fast. An the receiving end, this would maybe show as a
small jump. If a package with a chat message is lost, this is repeated and would introduce lag, even to all movement updates
after the message was created. In this case, the data is unrelated and should be put into different channels.

Channels
The DotNet clients and server are now supporting "channels". This allows you to separate information into multiple channels,
each being sequenced independently. This means, that Events ( see page 3) of one channel will not be stalled because
events ( see page 3) of another channel are not available.
By default an PhotonPeer ( see page 23) has two channels and channel zero is the default to send operations. The
operations join and leave are always sent in channel zero (for simplicity). There is a "background" channel 255 used
internally for connect and disconnect messages. This is ignored for the channel count.
Channels are prioritized: the lowest channel number is put into a UDP package first. Data in a higher channel might be sent
later when a UDP package is already full.
Example: The chat messages can now be sent in channel one, while movement is sent in channel zero. They are not related
and if a chat message is delayed, it will no longer affect movement in channel zero. Also, channel zero has higher priority
and is more likely to be sent (in case packages get filled up).

1.5 Using TCP


A PhotonPeer ( see page 23) could be instanced with TCP as underlying protocol if necessary. This is not best practice but
some platforms don't support UDP sockets. This is why Silverlight and Flash use TCP in all cases.
The Photon Client API is the same for both cases but there are some differences in what goes on below.
Everything sent over TCP is reliable. Automatically. And even if you call your operations as unreliable!

If you use only TCP clients


Simply send any operation unreliable. It saves some work (and bandwidth) in the underlying protocols.

If you have TCP and UDP clients


Anything you send between the TCP clients will always be transferred reliable. But as you communicate with some clients
that use UDP these will get your events ( see page 3) reliable or unreliable.

1.7 The Photon Server

Photon DotNet Client Documentation

Example:
A Silverlight client might send unreliable movement updates in channel # 1. This will be sent via TCP, which makes it
reliable. Photon however also has connections with UDP clients (like a 3D downloadable game client). It will use your
reliable / unreliable settings to forward your movement updates accordingly.

1.6 Serializable Datatypes

Starting with Photon Server SDK 1.8.0 and DotNet SDK 5.6.0, the set of serializable datatypes is changed. The ArrayList (
see page 10) was removed but aside from Arrays and Hashtables every serializable type can also be sent as array (e.g.
String[], Float[]). Only one-dimensional arrays are supported currently.

Photon 1.8.0 and higher


String / string
Boolean / bool
Byte / byte (unsigned! can be cast to SByte / sbyte to be eqivalent to Java's byte)
Int16 / short (signed)
Int32 / int (signed)
Int64 / long
Single / float
Double / double
Array (of the types above, with a max number of Short.MaxValue enties).
Hashtable (

see page 11) (not available as array)

The following data types can be used within events (

see page 3) as keys and values on Neutron:

Photon 1.6.0 and lower


String
Boolean
Byte / byte (unsigned! can be cast to SByte / sbyte to be equivalent to Java's byte)
Int16 (equals Short in Java)
Int32 (equals Integer in Java)
Int64 (equals Long in Java)
ArrayList (
Hashtable (

see page 10) (equals Vector in Java)


see page 11)

sbyte[]
int[]
String[]

1.8 Lite Application

Photon DotNet Client Documentation

Properties on Photon

1.7 The Photon Server


The Photon Server is the central hub for communication for all your clients. It is a service that can be run on any Windows
machine, handling the UDP and TCP connections of clients and hosting a DotNet runtime layer with your own business
logic, called application.
The Photon Server SDK includes several applications in source and pre-built. You can run them out of the box or develop
your own server logic.

Get the Photon Server SDK at: photon.exitgames.com

1.8 Lite Application


The Lite Application is the example application for room-based games on Photon and (hopefully) a flexible basis for your
own games. It offers rooms, joining and leaving them, sending events ( see page 3) to the other players in a room and
handles properties.
The Lite Application is tightly integrated with the client libraries and used as example throughout most documentation.

1.8.1 Properties on Photon


The Lite Application implements a general purpose mechanism to set and fetch key/value pairs on the server side (in
memory). They are associated to a room/game or a player within a room and can be fetched or updated by anyone in that
game.
Each entry in the properties Hashtable ( see page 11) is considered a separate property and can be overwritten
independently. The value of a property can be of any serializable datatype ( see page 5). The keys must be either of type
string or byte. Bytes are preferred, as they mean the less overhead.
To avoid confusion, don't mix string and byte as key-types. Mixed types of keys, require separate requests to fetch them.

Property broadcasting and events


Property changes in a game can be "broadcasted", which triggers events (
them. The player who changed the property does not get the update (again).

see page 3) for the other players to update

Any change that uses the broadcast option will trigger a property update event. This event carries the changed properties
(only), who changed the properties and where the properties belong to.

Your clients need to "merge" the changes (if properties are cached at all).
Properties can be set by these methods:
LitePeer.OpSetPropertiesOfActor Method (

see page 22) sets a player's properties

LitePeer.OpSetPropertiesOfGame Method (

see page 22) sets a game's properties

LitePeer.OpJoin Method (

see page 19) also allows you to set properties if the game did not exist yet
6

1.9 Further Help

Photon DotNet Client Documentation

And fetched with these methods:


OpGetPropertiesOfActor
OpGetPropertiesOfGame

Broadcast Events
Any change that uses the broadcast option will trigger a property update event LiteEventCode.SetProperties (
43). This event carries the properties as value of key LiteEventKey.Properties ( see page 44).
Additionally, there is information about who changed the properties in key LiteEventKey.ActorNr (

see page

see page 44).

The key LiteEventKey.TargetActorNr ( see page 44) will only be available if the property-set belongs to a certain player. If
it's not present, the properties are game-properties.

Notes
The current Lite application is not able to delete properties and does not support wildcard characters in string keys to fetch
properties.
Other types of keys could be used but to keep things simple, we decided against adding those. If needed, we would help you
with the implementation.
The property handling is likely to be updated and extended in the future.

1.9 Further Help


Developer Network
Visit: developer.exitgames.com
Developer Forum
Visit: forum.exitgames.com
Mail Support
Don't hesitate to mail us: developer@exitgames.com

2.2 Photon for Silverlight

Photon DotNet Client Documentation

2 DotNet Platforms
2.1 Photon for Unity3D
This chapter addresses differences between the DotNet SDK and the one for Unity3D.
If you don't use Unity3D, skip this chapter.

1. Supported versions of Unity:


a) Currently supported and tested Unity platforms are Standalone and Web (both Windows and MacOS) and iOS. The
export to PS3, Wii and Android are not tested by us currently but should be working as well.
b) Photon works fine with Unity Standard, with Unity Pro. Export to iOS devices might require a special Unity license.

2. Unity 3 and policy file requests


Starting with Unity 3.0, web players will require a policy file to connect to a different URL than their originating server. Photon
supports this feature out of the box. By default the server opens the a port for policy file requests (TCP port 843) and maps it
to the "Policy Application". We included source for this but in general it should be fine to just use deploy the binaries.

2
3. How to add Photon to your Unity project:
a) To add the Photon .dll from the SDK to a Unity project, just copy it somewhere in the assets-folder of the project and
make sure that there are no duplicates (pay attention to old versions with different filenames).
b) Make sure to have the following line of code somewhere in your scripts, so the game runs even when in background:
Application.runInBackground = true; //without this Photon will loose connection if not focussed
c) For the iOS builds, you should set the "iPhone Stripping Level" to "Strip Bytecode" (Edit->Project Settings->Player). Also,
use the "DotNet 2.0 subset". If your project runs fine in IDE and you get an error message when building it for device, please
check this option.
d) Make sure to change the server address used in the client, as "localhost:5055" won't work on device.

2.2 Photon for Silverlight


The Photon DotNet Client Library for Silverlight is based on the regular DotNet library (and shares its documentation).

Essential differences
No UDP
Silverlight does not support UDP sockets and thus all instanced PhotonPeers are using TCP. This affects Photon only.
No Port 5055
8

2.2 Photon for Silverlight

Photon DotNet Client Documentation

Again a change for Photon usage: you cannot select just any port with Silverlight. It needs to connect to ports in the range of:
4502-4534. We selected 4530 as connection port. You also need to have a Policy File Server running on port 843. Both TCP
ports must be open to the general internet to reach your server. The Photon Server SDK provides the correct setup.
No Hashtable (

see page 11) or ArrayList (

see page 10)

Silverlight excludes non-generic data types. As those are used throughout the libraries, we added the substitutes for those
classes. They are located in a separate library, so you could use Photon with Neutron in one project. Usage of those
substitutes should be analog to the DotNet Hashtable ( see page 11) and ArrayList ( see page 10).
Additional lib needed
In the Silverlight SDKs, we needed to split some classes from the Photon (and Neutron) libraries into a separate file.
Because of this, Silverlight projects have to both provided libraries / dlls of the Photon SDK.

The Demos
As usual, the demos are plain and consist of the least amount of UI possible (it's not our focus).
The Silverlight Photon Demo has its entry point in the Page.xaml.cs but most of the Photon logic is wrapped by the
Game.cs class. The sample should be compatible with the Realtime Demo of the DotNet SDK and others. Those however
are expanded more often.
If you need any further Silverlight demos we will help you. We just need to know.

3.1 Classes

Photon DotNet Client Documentation

ArrayList Class

3 Symbol Reference
3.1 Classes
The following table lists classes in this documentation.
Classes
Name
ArrayList (

Description
see page 10)

Hashtable (
LitePeer (

see page 11)


see page 13)

PhotonPeer (

see page 23)

SupportClass (

see page 36)

Silverlight only! This is a wrapper around a List<Object> as substitute for


the missing ArrayList class in Silverlight.
Silverlight only! This is a wrapper around a Dictionary<object,object> as
substitute for the missing Hashtable class in Silverlight.
A LitePeer is an extended PhotonPeer ( see page 23) and implements
the operations offered by the "Lite Application ( see page 6)" of the
Photon Server SDK.
Instances of the PhotonPeer class are used to connect to a Photon
server and communicate with it.
Contains conversion support elements such as classes, interfaces and
static methods.

3.1.1 ArrayList Class


Silverlight only! This is a wrapper around a List<Object> as substitute for the missing ArrayList class in Silverlight.
C#
public class ArrayList : List<Object>;
Notes
Supplied in separate library dll!
See: Photon for Silverlight (

see page 8)

Methods
Name
ArrayList (

Description
see page 11)

This is ArrayList, a member of class ArrayList.

ArrayList Fields
Name
SyncRoot (

Description
see page 11)

This is SyncRoot, a member of class ArrayList.

ArrayList Methods
Name
Synchronized (

Description
see page 11)

This is Synchronized, a member of class ArrayList.

3.1.1.1 ArrayList Constructor


10

3.1 Classes

Photon DotNet Client Documentation

Hashtable Class

3.1.1.1.1 ArrayList.ArrayList Constructor ()


C#
public ArrayList();
Description
This is ArrayList, a member of class ArrayList.

3.1.1.1.2 ArrayList.ArrayList Constructor (int)


C#
public ArrayList(int x);
Description
This is ArrayList, a member of class ArrayList.

3.1.1.2 ArrayList Fields


3.1.1.2.1 ArrayList.SyncRoot Field
C#
public Object SyncRoot = new Object();
Description
This is SyncRoot, a member of class ArrayList.

3.1.1.3 ArrayList Methods


3.1.1.3.1 ArrayList.Synchronized Method
C#
public static ArrayList Synchronized(ArrayList l);
Description
This is Synchronized, a member of class ArrayList.

3.1.2 Hashtable Class


Silverlight only! This is a wrapper around a Dictionary<object,object> as substitute for the missing Hashtable class in
Silverlight.
C#
public class Hashtable : Dictionary<object, object>;
Notes
Supplied in separate library dll!
See: Photon for Silverlight (

see page 8)

11

3.1 Classes

Photon DotNet Client Documentation

Hashtable Class

Methods
Name

Description

Hashtable (

see page 12)

This is Hashtable, a member of class Hashtable.

Hashtable Methods
Name

Description

Synchronized (
this (

see page 12)

see page 12)

ToString (

see page 13)

This is Synchronized, a member of class Hashtable.


This is this, a member of class Hashtable.
This is ToString, a member of class Hashtable.

3.1.2.1 Hashtable Constructor


3.1.2.1.1 Hashtable.Hashtable Constructor ()
C#
public Hashtable();
Description
This is Hashtable, a member of class Hashtable.

3.1.2.1.2 Hashtable.Hashtable Constructor (int)


C#
public Hashtable(int x);
Description
This is Hashtable, a member of class Hashtable.

3.1.2.2 Hashtable Methods


3.1.2.2.1 Hashtable.Synchronized Method
C#
public static Hashtable Synchronized(Hashtable t);
Description
This is Synchronized, a member of class Hashtable.

3.1.2.2.2 Hashtable.this Indexer


C#

public new object this[object key];


Description
This is this, a member of class Hashtable.

12

3.1 Classes

Photon DotNet Client Documentation

LitePeer Class

3.1.2.2.3 Hashtable.ToString Method


C#
public new String ToString();
Description
This is ToString, a member of class Hashtable.

3.1.3 LitePeer Class


A LitePeer is an extended PhotonPeer (
see page 6)" of the Photon Server SDK.

see page 23) and implements the operations offered by the "Lite Application (

C#
public class LitePeer : PhotonPeer;
Remarks
This class is used by our samples and allows rapid development of simple games. You can use rooms and properties and
send events ( see page 3). For many games, this is a good start.
Methods
Name

Description

PhotonPeer (

see page 26)

Creates a new PhotonPeer instance to communicate with Photon.


Connection is UDP based, except for Silverlight.

LitePeer Class
Name
LitePeer (

Description
see page 16)

Creates a LitePeer instance to connect and communicate with a Photon


server.
Uses UDP as protocol (except in the Silverlight library).

PhotonPeer Delegates
Name

Description

GetLocalMsTimestampDelegate (

see page 36) This is nested type PhotonPeer.GetLocalMsTimestampDelegate.

PhotonPeer Fields
Name

Description

PhotonPort (

see page 27)

The default port used with Photon as string. DotNet and Unity: "5055".
"4530" for Silverlight.

PhotonPeer Methods
Name
Connect (

Description
see page 27)

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.PeerStatusCallback ( see page 41) will be done. If
the connection can't be established, despite having a valid address, the
PeerStatusCallback is called with an error-value.
The appID 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,... more ( see page 27)
13

3.1 Classes

Photon DotNet Client Documentation


DeriveSharedKey (

Disconnect (

see page 28)

see page 28)

LitePeer Class

This method must be called with the OperationResult of


OpExchangeKeysForEncryption ( see page 30) to establish a shared
secret with the server and enable encryption.
If this is successful, the property IsEncryptionAvailable ( see page 33)
becomes true.
In OperationResult use this code to derive the shared secret: case
(byte)LiteOpCode.ExchangeKeysForEncryption:
//this.DebugReturn("OpExchangeKeysForEncryption ( see page 30)
response: " + SupportClass.HashtableToString ( see page
38)(returnValues)); if (returnCode == 0)
this.peer.DeriveSharedKey((byte[])returnValues[(byte)LiteOpKey.ServerK
ey]);
break;
This method disconnects from the Photon Server which will end
communication (if any).
Disconnect is also a command on the Server. The callback is a call to
nPeerReturn() ( see page 41) with a returnCode of
statusCode.Disconnect ( see page 48) and an operationCode of
LiteOpCode.Blank ( see page 45). If the client is disconnected already
or the connection thread is stopped, then there is no callback.
Disconnecting will also leave the joined game (if any) and trigger the
respective event (LiteEventCode.Leave ( see page 43)) for the
remaining players.

DispatchIncomingCommands (
see page 28)

This method directly causes the callbacks for events ( see page 3),
responses and state changes within a IPhotonPeerListener ( see page
39). 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
( see page 31)() until currently available commands are dispatched.

FetchServerTimestamp (
page 28)

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.

OpCustom (

see

see page 29)

Channel-less wrapper for OpCustom().

OpExchangeKeysForEncryption (
see page 30)

This method creates a public key for this client and exchanges it with the
server.
Encryption is not instantly available after calling this method. The fetched
server's public-key is provided by callback to OperationResult. See
DeriveSharedKey ( see page 28) how to go on after this operation.

SendOutgoingCommands (
page 30)

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 ( see page 31)().

Service (

see

see page 31)

StopThread (

This method excutes the internal send- and dispatch-processes in the


context/thread of an application.

see page 31)

This method immediately closes a connection (pure client side). If the


connections was open, this will trigger a disconnect callback to
PeerStatusCallback() with a returnCode of statusCode.Disconnect ( see
page 48) and an operationCode of LiteOpCode.Blank ( see page 45).

LitePeer Class
Name
OpGetProperties (

Description
see page 17)

OpGetPropertiesOfActor (
page 17)

see

Gets all properties of the game and each actor.


Gets selected properties of an actor.

14

3.1 Classes

Photon DotNet Client Documentation


OpGetPropertiesOfGame (
page 18)
OpJoin (

see

see page 19)

OpLeave (

Gets selected properties of current game.


This operation will join an existing room by name or create one if the
name is not in use yet.
Rooms (or games) are simply identified by name. We assume that users
always want to get into a room - no matter if it existed before or not, so it
might be a new one. If you want to make sure a room is created (new,
empty), the client side might come up with a unique name for it (make
sure the name was not taken yet).
The application "Lite Lobby" lists room names and effectively allows the
user to... more ( see page 19)

see page 20)

OpRaiseEvent (

LitePeer Class

Leave operation of the Lite Application (also in Lite Lobby). Leaves a


room / game, but keeps the connection. This operations triggers the
event LiteEventCode.Leave ( see page 43) for the remaining clients.
The event includes the actorNumber of the player who left in key
LiteEventKey.ActorNr ( see page 44).

see page 20)

OpSetPropertiesOfActor (
page 22)
OpSetPropertiesOfGame (
page 22)

Wrapper for OpRaiseEvent() without channel-parameter (will use channel


= 0).

see

Attaches or updates properties of an actor.

see

Attaches or updates properties of the current game.

PhotonPeer Properties
Name
BytesIn (

Description
see page 31)

BytesOut (

Count of all bytes coming in (including headers, excluding UDP/TCP


overhead)

see page 32)

ChannelCount (

see page 32)

CommandBufferSize (
32)
DebugOut (

Count of all bytes going out (including headers, excluding UDP/TCP


overhead)
Gets / sets the number of channels available in UDP connections with
Photon. Photon Channels are only supported for UDP. The default
ChannelCount is 2.

see page

see page 32)

Sets the level of debug output which is returned by the library (in
DebugReturn ( see page 40)).
Use the PhotonPeer.DebugLevel ( see page 43) enumeration. Default:
Error.

debugTimeForDeriveSharedKey (
see page 32)
debugTimeForDiffieHellman (
page 32)
DisconnectTimeout (

(Temporary property) Count of milliseconds that deriving the shared key


took. Available after OpExchangeKeysForEncryption ( see page 30)
and DeriveSharedKey ( see page 28) was called.

see (Temporary property) Count of milliseconds that the Diffie Hellman


algorithm needed to create the keys and provide a byte array of those.
Available after a call to OpExchangeKeysForEncryption ( see page 30).

see page 33) Milliseconds after which a reliable UDP command triggers a timeout
disconnect, unless acknowledged by server. This value currently only
affects UDP connections. The actual timeout might happen later,
depending on the connection. Commands that are sent while having a
bad roundtrip time and variance are checked less often for re-sending!
DisconnectTimeout and SentCountAllowance ( see page 34) are
competing settings: either might trigger a disconnect on the client first,
depending on the values and Rountrip Time. Default: 10000 ms.

IsEncryptionAvailable (
33)
Listener (

length of buffer - might be changed later on?!

see page 33)

see page

This property is set by OpExchangeKeysForEncryption ( see page 30)()


and DeriveSharedKey ( see page 28)(). While it's true, encryption can
be used for operations.
Gets the IPhotonPeerListener ( see page 39) of this instance (set in
constructor). Can be used in derived classes for Listener.DebugReturn().

15

3.1 Classes

Photon DotNet Client Documentation


LocalMsTimestampDelegate (
page 33)
LocalTimeInMilliSeconds (
page 33)
PeerID (

see This setter for a timestamp delegate which then replaces the default
Environment.TickCount with any equal function.

see

see page 33)

PeerState (

LitePeer Class

Gets a local timestamp in milliseconds by calling the


GetLocalMsTimestampDelegate ( see page 36). See
LocalMsTimestampDelegate ( see page 33).
This peer's ID as assigned by the server or 0 if not using UDP. Will be
0xFFFF before the client connects.

see page 34)

This is the (low level) state of the connection to the server of a


PhotonPeer ( see page 23). It is managed internally and read-only.

QueuedIncomingCommands (
see page 34)

Returns the sum of all currently received but not-yet-Dispatched reliable


commands (events ( see page 3) and operation results) from all
channels.

QueuedOutgoingCommands (
see page 34)

Sum of all commands currently queued as outgoing, including all


channels and reliable, unreliable.

RoundTripTime (

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.

see page 34)

RoundTripTimeVariance (
page 34)
SentCountAllowance (
34)

ServerAddress (

see

see page

see page 35)

ServerTimeInMilliSeconds (
page 35)
TimePingInterval (

WarningSize (

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 ( see page 33) and SentCountAllowance are
competing settings: either might trigger a disconnect on the client first,
depending on the values and Rountrip Time.
The server address which was used in PhotonPeer.Connect ( see
page 27)() or null (before Connect ( see page 27)() was called).

see

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

see page 35)

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 ( see page 34) calculation.

UseCommandActionQueue (
page 35)
UsedProtocol (

Changes of the roundtriptime as variance value. Gives a hint about how


much the time is changing.

see

see page 36)


see page 36)

This is UseCommandActionQueue, a member of class PhotonPeer.


The protocol this Peer uses to connect to Photon.
The WarningSize allows the PhotonPeer ( see page 23) class to test
each individual queue for congestion (in and out, reliable and unreliable).
If there are more commands than WarningSize in a queue, PhotonPeer
( see page 23) will call the PhotonPeerListener.PeerStatusCallback()
callback with a respective StatusCode ( see page 48).

3.1.3.1 LitePeer Constructor


3.1.3.1.1 LitePeer.LitePeer Constructor (IPhotonPeerListener)
Creates a LitePeer instance to connect and communicate with a Photon server.
16

3.1 Classes

Photon DotNet Client Documentation

LitePeer Class

Uses UDP as protocol (except in the Silverlight library).


C#
public LitePeer(IPhotonPeerListener listener);
Parameters
Parameters

Description

IPhotonPeerListener listener

Your IPhotonPeerListener (

see page 39) implementation.

3.1.3.1.2 LitePeer.LitePeer Constructor (IPhotonPeerListener,


ConnectionProtocol)
Creates a LitePeer instance to communicate with Photon and selects either UDP or TCP as protocol. We recommend UDP.
C#
public LitePeer(IPhotonPeerListener listener, ConnectionProtocol protocolType);
Parameters
Parameters

Description

IPhotonPeerListener listener

Your IPhotonPeerListener (

ConnectionProtocol protocolType

Protocol to use to connect to Photon.

see page 39) implementation.

3.1.3.1.3 LitePeer.LitePeer Constructor (IPhotonPeerListener, bool)


Deprecated. Please use: LitePeer(IPhotonPeerListener (
protocolType).

see page 39) listener, ConnectionProtocol (

see page 43)

C#
public LitePeer(IPhotonPeerListener listener, bool useTcp);

3.1.3.2 LitePeer Methods


3.1.3.2.1 LitePeer.OpGetProperties Method
Gets all properties of the game and each actor.
C#
public virtual short OpGetProperties(byte channelId);
Parameters
Parameters

Description

byte channelId

3.1.3.2.2 OpGetPropertiesOfActor Method


3
3.1.3.2.2.1 LitePeer.OpGetPropertiesOfActor Method (int[], byte[], byte)
Gets selected properties of an actor.
C#
public virtual short OpGetPropertiesOfActor(int[] actorNrList, byte[] properties, byte
channelId);

17

3.1 Classes

Photon DotNet Client Documentation

LitePeer Class

Parameters
Parameters

Description

int[] actorNrList

optional, a list of actornumbers to get the properties of

byte[] properties

optional, array of property keys to fetch

byte channelId

channel 0 or higher

Returns
Consecutive invocationID of the OP. Will throw Exception if not connected or channelId >= channelCount.
Description
Please read the general description of Properties on Photon (

see page 6).

3.1.3.2.2.2 LitePeer.OpGetPropertiesOfActor Method (int[], string[], byte)


Gets selected properties of an actor.
C#
public virtual short OpGetPropertiesOfActor(int[] actorNrList, string[] properties, byte
channelId);
Parameters
Parameters

Description

int[] actorNrList

optional, a list of actornumbers to get the properties of

string[] properties

optional, array of property keys to fetch

byte channelId

channel 0 or higher

Returns
Consecutive invocationID of the OP. Will throw Exception if not connected or channelId >= channelCount.
Description
Please read the general description of Properties on Photon (

see page 6).

3.1.3.2.3 OpGetPropertiesOfGame Method


3.1.3.2.3.1 LitePeer.OpGetPropertiesOfGame Method (byte[], byte)
Gets selected properties of current game.
C#
public virtual short OpGetPropertiesOfGame(byte[] properties, byte channelId);
Parameters
Parameters

Description

byte[] properties

array of property keys to fetch

byte channelId

channel 0 or higher

Returns
Consecutive invocationID of the OP. Will throw Exception if not connected or channelId >= channelCount.
Description
Please read the general description of Properties on Photon (

see page 6).

3.1.3.2.3.2 LitePeer.OpGetPropertiesOfGame Method (string[], byte)


Gets selected properties of current game.
18

3.1 Classes

Photon DotNet Client Documentation

LitePeer Class

C#
public virtual short OpGetPropertiesOfGame(string[] properties, byte channelId);
Parameters
Parameters

Description

string[] properties

array of property keys to fetch

byte channelId

channel 0 or higher

Returns
Consecutive invocationID of the OP. Will throw Exception if not connected or channelId >= channelCount.
Description
Please read the general description of Properties on Photon (

see page 6).

3.1.3.2.4 OpJoin Method


3.1.3.2.4.1 LitePeer.OpJoin Method (string)
This operation will join an existing room by name or create one if the name is not in use yet.
Rooms (or games) are simply identified by name. We assume that users always want to get into a room - no matter if it
existed before or not, so it might be a new one. If you want to make sure a room is created (new, empty), the client side
might come up with a unique name for it (make sure the name was not taken yet).
The application "Lite Lobby" lists room names and effectively allows the user to select a distinct one.
Each actor (a.k.a. player) in a room will get events (

see page 3) that are raised for the room by any player.

To distinguish the actors, each gets a consecutive actornumber. This is used in events ( see page 3) to mark who triggered
the event. A client finds out it's own actornumber in the return callback for operation Join. Number 1 is the lowest
actornumber in each room and the client with that actornumber created the room.
Each client could easily send custom data around. If the data should be available to newcomers, it makes sense to use
Properties.
Joining a room will trigger the event LiteEventCode.Join ( see page 43), which contains the list of actorNumbers of current
players inside the room (LiteEventKey.ActorList ( see page 44)). This also gives you a count of current players.
C#
public virtual short OpJoin(string gameName);
Parameters
Parameters

Description

string gameName

Any identifying name for a room / game.

Returns
Consecutive invocationID of the OP. Will throw Exception if not connected.

3.1.3.2.4.2 LitePeer.OpJoin Method (string, Hashtable, Hashtable, bool)

This operation will join an existing room by name or create one if the name is not in use yet.
Rooms (or games) are simply identified by name. We assume that users always want to get into a room - no matter if it
existed before or not, so it might be a new one. If you want to make sure a room is created (new, empty), the client side
might come up with a unique name for it (make sure the name was not taken yet).
The application "Lite Lobby" lists room names and effectively allows the user to select a distinct one.
Each actor (a.k.a. player) in a room will get events (

see page 3) that are raised for the room by any player.
19

3.1 Classes

Photon DotNet Client Documentation

LitePeer Class

To distinguish the actors, each gets a consecutive actornumber. This is used in events ( see page 3) to mark who triggered
the event. A client finds out it's own actornumber in the return callback for operation Join. Number 1 is the lowest
actornumber in each room and the client with that actornumber created the room.
Each client could easily send custom data around. If the data should be available to newcomers, it makes sense to use
Properties.
Joining a room will trigger the event LiteEventCode.Join ( see page 43), which contains the list of actorNumbers of current
players inside the room (LiteEventKey.ActorList ( see page 44)). This also gives you a count of current players.
C#
public virtual short OpJoin(string gameName, Hashtable gameProperties, Hashtable
actorProperties, bool broadcastActorProperties);
Parameters
Parameters

Description

string gameName

Any identifying name for a room / game.

Hashtable gameProperties

optional, set of game properties, by convention: only used if


game is new/created

Hashtable actorProperties

optional, set of actor properties

bool broadcastActorProperties

optional, broadcast actor proprties in join-event

Returns
Consecutive invocationID of the OP. Will throw Exception if not connected.

3.1.3.2.5 OpLeave Method


3.1.3.2.5.1 LitePeer.OpLeave Method ()
Leave operation of the Lite Application (also in Lite Lobby). Leaves a room / game, but keeps the connection. This
operations triggers the event LiteEventCode.Leave ( see page 43) for the remaining clients. The event includes the
actorNumber of the player who left in key LiteEventKey.ActorNr ( see page 44).
C#
public virtual short OpLeave();
Returns
Consecutive invocationID of the OP. Will throw Exception if not connected.

3.1.3.2.5.2 LitePeer.OpLeave Method (String)


Deprecated. Please use OpLeave() without the gameName parameter (it's not checked server side).
C#
public virtual short OpLeave(String gameName);
Returns
Consecutive invocationID of the OP. Will throw Exception if not connected.

3.1.3.2.6 OpRaiseEvent Method


3.1.3.2.6.1 LitePeer.OpRaiseEvent Method (byte, Hashtable, bool)
Wrapper for OpRaiseEvent() without channel-parameter (will use channel = 0).
C#
public virtual short OpRaiseEvent(byte eventCode, Hashtable evData, bool sendReliable);
20

3.1 Classes

Photon DotNet Client Documentation

LitePeer Class

Parameters
Parameters

Description

byte eventCode
Hashtable evData
bool sendReliable
Returns
Consecutive invocationID of the OP. Will throw Exception if not connected.

3.1.3.2.6.2 LitePeer.OpRaiseEvent Method (byte, Hashtable, bool, byte)


This method raises an event which is sent to the other players of a game.
C#
public virtual short OpRaiseEvent(byte eventCode, Hashtable evData, bool sendReliable, byte
channelId);
Parameters
Parameters

Description

byte eventCode

the eventCode (used in callback


IPhotonPeerListener.EventAction (
receiving parties

see page 40)) on

Hashtable evData

the event's data in form of a Hashtable (

bool sendReliable

true sends the event reliable, false sends unreliable

see page 11)

byte channelId

number of channel to use (starting with 0)

Returns
Consecutive invocationID of the OP. Will throw Exception if not connected or channelId >= channelCount.
Remarks
RaiseEvent can be used reliable or unreliable. Both result in ordered events ( see page 3) but the unreliable ones might be
lost and allow gaps in the resulting event sequence. On the other hand, they cause less overhead and are optimal for data
that is replaced soon. Sending is not done immediately but in intervals of Service ( see page 31) calls.
The parameter eventCode defines the event's type and eventCode-value on the receiving clients. The parameter "evData" is
a Hashtable ( see page 11) which can have any number of keys and values of the serializable datatypes ( see page 5). It
will be copied to the resulting event Hashtable ( see page 11) as value of key: LiteEventKey.Data ( see page 44).
It is recommended to keep keys (and data) as simple as possible (e.g. Byte or Short as key and byte[] as value), as the data
is typically sent multiple times per second. This would add up to a huge amount of data in itself otherwise.
Example
//send some position data:
Hashtable evInfo = new Hashtable();
Player local = (Player)players[playerLocalID];
evInfo.Add((Object)STATUS_PLAYER_POS_X, (Int32)local.posX);
evInfo.Add((Object)STATUS_PLAYER_POS_Y, (Int32)local.posY);
peer.OpRaiseEvent(EV_MOVE, evInfo, true); //EV_MOVE = 101

//receive said data in eventAction():


Hashtable data = (Hashtable)photonEvent[LiteEventKey.Data];
switch (eventCode) {
case EV_MOVE:
//101 in this sample
p = (Player)players[actorNr];
if (p != null) {
p.posX = (int)data[(Byte)STATUS_PLAYER_POS_X];
p.posY = (int)data[(Byte)STATUS_PLAYER_POS_Y];
}
break;
Events (

see page 3) from the Photon Server are not pushed through the regular Protocol library. Instead they are received
21

3.1 Classes

Photon DotNet Client Documentation

and internally buffered until they are Dispatched (

LitePeer Class

see page 28).

3.1.3.2.6.3 LitePeer.OpRaiseEvent Method (byte, Hashtable, bool, byte, int[])


Extended Operation Raise Event (

see page 3) with optional target actor list.

C#
public virtual short OpRaiseEvent(byte eventCode, Hashtable evData, bool sendReliable, byte
channelId, int[] targetActors);
Parameters
Parameters

Description

byte eventCode

the eventCode (used in callback


IPhotonPeerListener.EventAction (
receiving parties

see page 40)) on

Hashtable evData

the event's data in form of a Hashtable (

bool sendReliable

true sends the event reliable, false sends unreliable

see page 11)

int[] targetActors

list of actorNumbers which should receive this event. if null,


ALL OTHER players in room will get the event.

Returns
Consecutive invocationID of the OP. Will throw Exception if not connected or channelId >= channelCount.
Remarks
This variant works like the regular OpRaiseEvent methods. Please read the documentation of these ( see page 21). This
variant has an optional list of target actors. If set, the server will send the event only to the room's actors defined by the list.
This can be used to implement private messages inside a room or similar.

3.1.3.2.7 LitePeer.OpSetPropertiesOfActor Method


Attaches or updates properties of an actor.
C#
public virtual short OpSetPropertiesOfActor(int actorNr, Hashtable properties, bool
broadcast, byte channelId);
Parameters
Parameters

Description

int actorNr

the actorNr is used to identify a player/peer in a game

Hashtable properties

hashtable containing the properties to add or overwrite

bool broadcast

true will trigger an event LiteEventKey.SetProperties with the


updated properties in it

byte channelId

channel 0 or higher

Returns
Consecutive invocationID of the OP. Will throw Exception if not connected or channelId >= channelCount.
Description
Please read the general description of Properties on Photon (

see page 6).

3.1.3.2.8 LitePeer.OpSetPropertiesOfGame Method


Attaches or updates properties of the current game.
C#
public virtual short OpSetPropertiesOfGame(Hashtable properties, bool broadcast, byte
channelId);
22

3.1 Classes

Photon DotNet Client Documentation

PhotonPeer Class

Parameters
Parameters

Description

Hashtable properties

hashtable containing the properties to add or overwrite

bool broadcast

true will trigger an event LiteEventKey.SetProperties with the


updated properties in it

byte channelId

channel 0 or higher

Returns
Consecutive invocationID of the OP. Will throw Exception if not connected or channelId >= channelCount.
Description
Please read the general description of Properties on Photon (

see page 6).

3.1.4 PhotonPeer Class


Instances of the PhotonPeer class are used to connect to a Photon server and communicate with it.
C#
public class PhotonPeer;
Remarks
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 ( see page 3).
Methods
Name
PhotonPeer (

Description
see page 26)

Creates a new PhotonPeer instance to communicate with Photon.


Connection is UDP based, except for Silverlight.

PhotonPeer Delegates
Name

Description

GetLocalMsTimestampDelegate (

see page 36) This is nested type PhotonPeer.GetLocalMsTimestampDelegate.

PhotonPeer Fields
Name
PhotonPort (

Description
see page 27)

The default port used with Photon as string. DotNet and Unity: "5055".
"4530" for Silverlight.

23

3.1 Classes

Photon DotNet Client Documentation

PhotonPeer Class

PhotonPeer Methods
Name
Connect (

Description
see page 27)

DeriveSharedKey (

Disconnect (

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.PeerStatusCallback ( see page 41) will be done. If
the connection can't be established, despite having a valid address, the
PeerStatusCallback is called with an error-value.
The appID 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,... more ( see page 27)

see page 28)

see page 28)

This method must be called with the OperationResult of


OpExchangeKeysForEncryption ( see page 30) to establish a shared
secret with the server and enable encryption.
If this is successful, the property IsEncryptionAvailable ( see page 33)
becomes true.
In OperationResult use this code to derive the shared secret: case
(byte)LiteOpCode.ExchangeKeysForEncryption:
//this.DebugReturn("OpExchangeKeysForEncryption ( see page 30)
response: " + SupportClass.HashtableToString ( see page
38)(returnValues)); if (returnCode == 0)
this.peer.DeriveSharedKey((byte[])returnValues[(byte)LiteOpKey.ServerK
ey]);
break;
This method disconnects from the Photon Server which will end
communication (if any).
Disconnect is also a command on the Server. The callback is a call to
nPeerReturn() ( see page 41) with a returnCode of
statusCode.Disconnect ( see page 48) and an operationCode of
LiteOpCode.Blank ( see page 45). If the client is disconnected already
or the connection thread is stopped, then there is no callback.
Disconnecting will also leave the joined game (if any) and trigger the
respective event (LiteEventCode.Leave ( see page 43)) for the
remaining players.

DispatchIncomingCommands (
see page 28)

This method directly causes the callbacks for events ( see page 3),
responses and state changes within a IPhotonPeerListener ( see page
39). 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
( see page 31)() until currently available commands are dispatched.

FetchServerTimestamp (
page 28)

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.

OpCustom (

see

see page 29)

OpExchangeKeysForEncryption (
see page 30)

Channel-less wrapper for OpCustom().


This method creates a public key for this client and exchanges it with the
server.
Encryption is not instantly available after calling this method. The fetched
server's public-key is provided by callback to OperationResult. See
DeriveSharedKey ( see page 28) how to go on after this operation.

24

3.1 Classes

Photon DotNet Client Documentation


SendOutgoingCommands (
page 30)
Service (

see

see page 31)

StopThread (

PhotonPeer Class

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 ( see page 31)().
This method excutes the internal send- and dispatch-processes in the
context/thread of an application.

see page 31)

This method immediately closes a connection (pure client side). If the


connections was open, this will trigger a disconnect callback to
PeerStatusCallback() with a returnCode of statusCode.Disconnect ( see
page 48) and an operationCode of LiteOpCode.Blank ( see page 45).

PhotonPeer Properties
Name

Description

BytesIn (

see page 31)

BytesOut (

Count of all bytes coming in (including headers, excluding UDP/TCP


overhead)

see page 32)

ChannelCount (

see page 32)

CommandBufferSize (
32)
DebugOut (

Count of all bytes going out (including headers, excluding UDP/TCP


overhead)
Gets / sets the number of channels available in UDP connections with
Photon. Photon Channels are only supported for UDP. The default
ChannelCount is 2.

see page

see page 32)

Sets the level of debug output which is returned by the library (in
DebugReturn ( see page 40)).
Use the PhotonPeer.DebugLevel ( see page 43) enumeration. Default:
Error.

debugTimeForDeriveSharedKey (
see page 32)
debugTimeForDiffieHellman (
page 32)
DisconnectTimeout (

see (Temporary property) Count of milliseconds that the Diffie Hellman


algorithm needed to create the keys and provide a byte array of those.
Available after a call to OpExchangeKeysForEncryption ( see page 30).

see page

see page 33)

LocalTimeInMilliSeconds (
page 33)

see

see page 33)

PeerState (

This property is set by OpExchangeKeysForEncryption ( see page 30)()


and DeriveSharedKey ( see page 28)(). While it's true, encryption can
be used for operations.
Gets the IPhotonPeerListener ( see page 39) of this instance (set in
constructor). Can be used in derived classes for Listener.DebugReturn().

LocalMsTimestampDelegate (
page 33)

PeerID (

(Temporary property) Count of milliseconds that deriving the shared key


took. Available after OpExchangeKeysForEncryption ( see page 30)
and DeriveSharedKey ( see page 28) was called.

see page 33) Milliseconds after which a reliable UDP command triggers a timeout
disconnect, unless acknowledged by server. This value currently only
affects UDP connections. The actual timeout might happen later,
depending on the connection. Commands that are sent while having a
bad roundtrip time and variance are checked less often for re-sending!
DisconnectTimeout and SentCountAllowance ( see page 34) are
competing settings: either might trigger a disconnect on the client first,
depending on the values and Rountrip Time. Default: 10000 ms.

IsEncryptionAvailable (
33)
Listener (

length of buffer - might be changed later on?!

see page 34)

see This setter for a timestamp delegate which then replaces the default
Environment.TickCount with any equal function.
Gets a local timestamp in milliseconds by calling the
GetLocalMsTimestampDelegate ( see page 36). See
LocalMsTimestampDelegate ( see page 33).

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


0xFFFF before the client connects.
This is the (low level) state of the connection to the server of a
PhotonPeer. It is managed internally and read-only.

QueuedIncomingCommands (
see page 34)

Returns the sum of all currently received but not-yet-Dispatched reliable


commands (events ( see page 3) and operation results) from all
channels.

QueuedOutgoingCommands (
see page 34)

Sum of all commands currently queued as outgoing, including all


channels and reliable, unreliable.
25

3.1 Classes

Photon DotNet Client Documentation


RoundTripTime (

see page 34)

RoundTripTimeVariance (
page 34)
SentCountAllowance (
34)

ServerAddress (

see

see page

see page 35)

ServerTimeInMilliSeconds (
page 35)
TimePingInterval (

WarningSize (

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.
Changes of the roundtriptime as variance value. Gives a hint about how
much the time is changing.
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 ( see page 33) and SentCountAllowance are
competing settings: either might trigger a disconnect on the client first,
depending on the values and Rountrip Time.
The server address which was used in PhotonPeer.Connect ( see
page 27)() or null (before Connect ( see page 27)() was called).

see

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

see page 35)

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 ( see page 34) calculation.

UseCommandActionQueue (
page 35)
UsedProtocol (

PhotonPeer Class

see

see page 36)


see page 36)

This is UseCommandActionQueue, a member of class PhotonPeer.


The protocol this Peer uses to connect to Photon.
The WarningSize allows the PhotonPeer class to test each individual
queue for congestion (in and out, reliable and unreliable). If there are
more commands than WarningSize in a queue, PhotonPeer will call the
PhotonPeerListener.PeerStatusCallback() callback with a respective
StatusCode ( see page 48).

3.1.4.1 PhotonPeer Constructor


3.1.4.1.1 PhotonPeer.PhotonPeer Constructor (IPhotonPeerListener)
Creates a new PhotonPeer instance to communicate with Photon.
Connection is UDP based, except for Silverlight.
C#
public PhotonPeer(IPhotonPeerListener listener);

Parameters
Parameters

Description

IPhotonPeerListener listener

a IPhotonPeerListener (

see page 39) implementation

3.1.4.1.2 PhotonPeer.PhotonPeer Constructor (IPhotonPeerListener,


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

3.1 Classes

Photon DotNet Client Documentation

PhotonPeer Class

recommend UDP.
C#
public PhotonPeer(IPhotonPeerListener listener, ConnectionProtocol protocolType);
Parameters
Parameters

Description

IPhotonPeerListener listener

a IPhotonPeerListener (

ConnectionProtocol protocolType

Protocol to use to connect to Photon.

see page 39) implementation

3.1.4.1.3 PhotonPeer.PhotonPeer Constructor (IPhotonPeerListener, bool)


Deprecated. Please use: PhotonPeer(IPhotonPeerListener (
protocolType).

see page 39) listener, ConnectionProtocol (

see page 43)

C#
public PhotonPeer(IPhotonPeerListener listener, bool useTcp);

3.1.4.2 PhotonPeer Fields


3.1.4.2.1 PhotonPeer.PhotonPort Field
The default port used with Photon as string. DotNet and Unity: "5055". "4530" for Silverlight.
C#
public static readonly string PhotonPort = "4530";

3.1.4.3 PhotonPeer Methods


3.1.4.3.1 PhotonPeer.Connect Method
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.PeerStatusCallback ( see page 41) will be done. If
the connection can't be established, despite having a valid address, the PeerStatusCallback is called with an error-value.
The appID 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 appId / name is "Lite" but other samples use "LiteLobby" and "MmoDemo" in Connect(). You can setup your
own application and name it any way you like.
C#

public virtual bool Connect(String serverAddress, String appID);


Parameters
Parameters

Description

String serverAddress

Address of the Photon server. Format: ip:port (e.g.


127.0.0.1:5055) or hostname:port (e.g. localhost:5055)

String appID

The name of the application to use within Photon. This


should match a "Name" for an application, which are setup in
your server's config.

27

3.1 Classes

Photon DotNet Client Documentation

PhotonPeer Class

Returns
true if IP is available (DNS name is resolved) and server is being connected. false on error.

3.1.4.3.2 PhotonPeer.DeriveSharedKey Method


This method must be called with the OperationResult of OpExchangeKeysForEncryption (
shared secret with the server and enable encryption.
If this is successful, the property IsEncryptionAvailable (

see page 30) to establish a

see page 33) becomes true.

In OperationResult use this code to derive the shared secret: case (byte)LiteOpCode.ExchangeKeysForEncryption:
//this.DebugReturn("OpExchangeKeysForEncryption ( see page 30) response: " + SupportClass.HashtableToString ( see
page 38)(returnValues)); if (returnCode == 0) this.peer.DeriveSharedKey((byte[])returnValues[(byte)LiteOpKey.ServerKey]);
break;
C#
public void DeriveSharedKey(byte[] serverPublicKey);
Parameters
Parameters

Description

byte[] serverPublicKey

3.1.4.3.3 PhotonPeer.Disconnect Method


This method disconnects from the Photon Server which will end communication (if any).
Disconnect is also a command on the Server. The callback is a call to nPeerReturn() ( see page 41) with a returnCode of
statusCode.Disconnect ( see page 48) and an operationCode of LiteOpCode.Blank ( see page 45). If the client is
disconnected already or the connection thread is stopped, then there is no callback.
Disconnecting will also leave the joined game (if any) and trigger the respective event (LiteEventCode.Leave (
43)) for the remaining players.

see page

C#
public virtual void Disconnect();

3.1.4.3.4 PhotonPeer.DispatchIncomingCommands Method


This method directly causes the callbacks for events ( see page 3), responses and state changes within a
IPhotonPeerListener ( see page 39). 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
( see page 31)() until currently available commands are dispatched.
C#
public virtual bool DispatchIncomingCommands();
Remarks
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 ( see page 3)).
The callbacks to the peer's IPhotonPeerListener ( see page 39) are executed in the same thread that is calling
DispatchIncomingCommands. This makes things easier in a game loop: Event ( see page 3) execution won't clash with
painting objects or the game logic.

3.1.4.3.5 PhotonPeer.FetchServerTimestamp Method


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

3.1 Classes

Photon DotNet Client Documentation

PhotonPeer Class

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.
C#
public virtual void FetchServerTimestamp();

3.1.4.3.6 OpCustom Method


3.1.4.3.6.1 PhotonPeer.OpCustom Method (byte, Hashtable, bool)
Channel-less wrapper for OpCustom().
C#
public virtual short OpCustom(byte customOpCode, Hashtable customOpParameters, bool
sendReliable);
Parameters
Parameters

Description

byte customOpCode
Hashtable customOpParameters
bool sendReliable
Returns
Consecutive invocationID of the OP. Will throw Exception if not connected or channelId >= channelCount.

3.1.4.3.6.2 PhotonPeer.OpCustom Method (byte, Hashtable, bool, byte)


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 "Custom Operations (

see page 2)".

C#
public virtual short OpCustom(byte customOpCode, Hashtable customOpParameters, bool
sendReliable, byte channelId);
Parameters
Parameters

Description

byte customOpCode

Operations ( see page 2) are handled by their byte-typed


code. The codes of the "Lite" application are in the struct
LiteOpCode ( see page 45).

Hashtable customOpParameters

A Hashtable ( see page 11) containing parameters as


key-value pair. The key is byte-typed, while the value is any
serializable datatype.

bool sendReliable

Selects if the operation must be acknowledged or not. If


false, the operation is not guaranteed to reach the server.

byte channelId

The channel in which this operation should be sent.

Returns
Consecutive invocationID of the OP. Will throw Exception if not connected or channelId >= channelCount.

29

3.1 Classes

Photon DotNet Client Documentation

PhotonPeer Class

3.1.4.3.6.3 PhotonPeer.OpCustom Method (byte, Hashtable, bool, byte, bool)


Variant of OpCustom with encryption parameter. To be used after OpExchangeKeysForEncryption (
DeriveSharedKey ( see page 28).

see page 30) and

C#
public virtual short OpCustom(byte customOpCode, Hashtable customOpParameters, bool
sendReliable, byte channelId, bool encrypt);
Parameters
Parameters

Description

byte customOpCode

Operations ( see page 2) are handled by their byte-typed


code. The codes of the "Lite" application are in the struct
LiteOpCode ( see page 45).

Hashtable customOpParameters

A Hashtable ( see page 11) containing parameters as


key-value pair. The key is byte-typed, while the value is any
serializable datatype.

bool sendReliable

Selects if the operation must be acknowledged or not. If


false, the operation is not guaranteed to reach the server.

byte channelId

The channel in which this operation should be sent.

bool encrypt

Can only be true, while IsEncryptionAvailable (


33) is true, too.

see page

3.1.4.3.7 PhotonPeer.OpExchangeKeysForEncryption Method


This method creates a public key for this client and exchanges it with the server.
Encryption is not instantly available after calling this method. The fetched server's public-key is provided by callback to
OperationResult. See DeriveSharedKey ( see page 28) how to go on after this operation.
C#
public short OpExchangeKeysForEncryption();
Returns
Invocation ID or -1 if it failed (not connected).
Remarks
This method must be called before the "encrypt" parameter of OpCustom (
method, the property IsEncryptionAvailable ( see page 33) becomes false.

see page 29) can be used. When you call this

3.1.4.3.8 PhotonPeer.SendOutgoingCommands Method


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 ( see page 31)().
C#
public virtual void SendOutgoingCommands();
Remarks

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 ( see page 31).
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.
30

3.1 Classes

Photon DotNet Client Documentation

PhotonPeer Class

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

3.1.4.3.9 PhotonPeer.Service Method


This method excutes the internal send- and dispatch-processes in the context/thread of an application.
C#
public virtual void Service();
Remarks
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 ( see page 3) 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 ( see page 28) and SendOutgoingCommands ( see page 30).
Call this method regularly (2..20 times a second).
This will Dispatch ANY remaining buffered responses and events ( see page 3) 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.
See Also
PhotonPeer.DispatchIncomingCommands (

see page 28), PhotonPeer.SendOutgoingCommands (

see page 30)

Example
You could replace Service by:
while (DispatchIncomingCommands (
see page 28)()); //Dispatch until everything
SendOutgoingCommands ( see page 30)(); //Send a UDP/TCP package with outgoing messages

is

Dispatched...

3.1.4.3.10 PhotonPeer.StopThread Method


This method immediately closes a connection (pure client side). If the connections was open, this will trigger a disconnect
callback to PeerStatusCallback() with a returnCode of statusCode.Disconnect ( see page 48) and an operationCode of
LiteOpCode.Blank ( see page 45).
C#
public virtual void StopThread();
Todo
change description to include the closing of the connection! alternative: use disconnect

3.1.4.4 PhotonPeer Properties


3

3.1.4.4.1 PhotonPeer.BytesIn Property


Count of all bytes coming in (including headers, excluding UDP/TCP overhead)
C#
public long BytesIn;

31

3.1 Classes

Photon DotNet Client Documentation

PhotonPeer Class

3.1.4.4.2 PhotonPeer.BytesOut Property


Count of all bytes going out (including headers, excluding UDP/TCP overhead)
C#
public long BytesOut;

3.1.4.4.3 PhotonPeer.ChannelCount Property


Gets / sets the number of channels available in UDP connections with Photon. Photon Channels are only supported for
UDP. The default ChannelCount is 2.
C#
public byte ChannelCount;

3.1.4.4.4 PhotonPeer.CommandBufferSize Property


C#
public int CommandBufferSize;
Description
length of buffer - might be changed later on?!

3.1.4.4.5 PhotonPeer.DebugOut Property


Sets the level of debug output which is returned by the library (in DebugReturn (
Use the PhotonPeer.DebugLevel (

see page 40)).

see page 43) enumeration. Default: Error.

C#
public DebugLevel DebugOut;

3.1.4.4.6 PhotonPeer.debugTimeForDeriveSharedKey Property


(Temporary property) Count
OpExchangeKeysForEncryption (

of milliseconds that deriving


see page 30) and DeriveSharedKey (

the shared key took.


see page 28) was called.

Available

after

C#
public int debugTimeForDeriveSharedKey;
Remarks
This temporary property might be removed in upcoming SDK releases.

3.1.4.4.7 PhotonPeer.debugTimeForDiffieHellman Property


(Temporary property) Count of milliseconds that the Diffie Hellman algorithm needed to create the keys and provide a byte
array of those. Available after a call to OpExchangeKeysForEncryption ( see page 30).

C#
public int debugTimeForDiffieHellman;
Remarks
This temporary property might be removed in upcoming SDK releases.

32

3.1 Classes

Photon DotNet Client Documentation

PhotonPeer Class

3.1.4.4.8 PhotonPeer.DisconnectTimeout Property


Milliseconds after which a reliable UDP command triggers a timeout disconnect, unless acknowledged by server. This value
currently only affects UDP connections. The actual timeout might happen later, depending on the connection. Commands
that are sent while having a bad roundtrip time and variance are checked less often for re-sending!
DisconnectTimeout and SentCountAllowance ( see page 34) are competing settings: either might trigger a disconnect on
the client first, depending on the values and Rountrip Time. Default: 10000 ms.
C#
public int DisconnectTimeout;

3.1.4.4.9 PhotonPeer.IsEncryptionAvailable Property


This property is set by OpExchangeKeysForEncryption (
true, encryption can be used for operations.

see page 30)() and DeriveSharedKey (

see page 28)(). While it's

C#
public bool IsEncryptionAvailable;

3.1.4.4.10 PhotonPeer.Listener Property


Gets the IPhotonPeerListener (
Listener.DebugReturn().

see page 39) of this instance (set in constructor). Can be used in derived classes for

C#
public IPhotonPeerListener Listener;

3.1.4.4.11 PhotonPeer.LocalMsTimestampDelegate Property


This setter for a timestamp delegate which then replaces the default Environment.TickCount with any equal function.
C#
public GetLocalMsTimestampDelegate LocalMsTimestampDelegate;
Remarks
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
Exceptions

Description

Exception

Exception is thrown peer.PeerState (


PS_DISCONNECTED.

see page 34) is not

3.1.4.4.12 PhotonPeer.LocalTimeInMilliSeconds Property


Gets a local timestamp in milliseconds by calling the GetLocalMsTimestampDelegate (
LocalMsTimestampDelegate ( see page 33).

see page 36). See

C#
public int LocalTimeInMilliSeconds;

3.1.4.4.13 PhotonPeer.PeerID Property


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

3.1 Classes

Photon DotNet Client Documentation

PhotonPeer Class

C#
public ushort PeerID;
Remarks
Used for debugging only. This value is not useful in everyday Photon usage.

3.1.4.4.14 PhotonPeer.PeerState Property


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

see page 23). It is managed internally and

C#
public PeerStateValue PeerState;
Remarks
Don't mix this up with the StatusCode ( see page 48) provided in IPhotonListener.PeerStatusCallback(). Applications
should use the StatusCode ( see page 48) of PeerStatusCallback() to track their state, as it also covers the higher level
initialization between a client and Photon.

3.1.4.4.15 PhotonPeer.QueuedIncomingCommands Property


Returns the sum of all currently received but not-yet-Dispatched reliable commands (events (
results) from all channels.

see page 3) and operation

C#
public int QueuedIncomingCommands;

3.1.4.4.16 PhotonPeer.QueuedOutgoingCommands Property


Sum of all commands currently queued as outgoing, including all channels and reliable, unreliable.
C#
public int QueuedOutgoingCommands;

3.1.4.4.17 PhotonPeer.RoundTripTime Property


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.
C#
public int RoundTripTime;

3.1.4.4.18 PhotonPeer.RoundTripTimeVariance Property

Changes of the roundtriptime as variance value. Gives a hint about how much the time is changing.
C#
public int RoundTripTimeVariance;

3.1.4.4.19 PhotonPeer.SentCountAllowance Property


Number of send retries before a peer is considered lost/disconnected. Default: 5. The initial timeout countdown of a
34

3.1 Classes

Photon DotNet Client Documentation

PhotonPeer Class

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 ( see page 33) and SentCountAllowance are competing settings: either might trigger a disconnect on
the client first, depending on the values and Rountrip Time.
C#
public int SentCountAllowance;

3.1.4.4.20 PhotonPeer.ServerAddress Property


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

see page 27)() or null (before Connect (

see page 27)()

C#
public string ServerAddress;

3.1.4.4.21 PhotonPeer.ServerTimeInMilliSeconds Property


Approximated Environment.TickCount value of server (while connected).
C#
public int ServerTimeInMilliSeconds;
Description
0 until connected. While connected, the value is an approximation of the server's current timestamp.
Remarks
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 ( see page 28)() 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 (
values (this property returns a new value per tick).

see page 33) to calculate in-between

The value sent by Photon equals Environment.TickCount in the logic layer (e.g. Lite).

3.1.4.4.22 PhotonPeer.TimePingInterval Property


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 ( see page 34) calculation.
C#
public int TimePingInterval;

3.1.4.4.23 PhotonPeer.UseCommandActionQueue Property


C#
public bool UseCommandActionQueue;
Description
This is UseCommandActionQueue, a member of class PhotonPeer.

35

3.1 Classes

Photon DotNet Client Documentation

SupportClass Class

3.1.4.4.24 PhotonPeer.UsedProtocol Property


The protocol this Peer uses to connect to Photon.
C#
public ConnectionProtocol UsedProtocol;

3.1.4.4.25 PhotonPeer.WarningSize Property


The WarningSize allows the PhotonPeer ( see page 23) class to test each individual queue for congestion (in and out,
reliable and unreliable). If there are more commands than WarningSize in a queue, PhotonPeer ( see page 23) will call the
PhotonPeerListener.PeerStatusCallback() callback with a respective StatusCode ( see page 48).
C#
public int WarningSize;

3.1.4.5 PhotonPeer Delegates


3.1.4.5.1 PhotonPeer.GetLocalMsTimestampDelegate Delegate
C#
public delegate int GetLocalMsTimestampDelegate();
Description
This is nested type PhotonPeer.GetLocalMsTimestampDelegate.

3.1.5 SupportClass Class


Contains conversion support elements such as classes, interfaces and static methods.
C#
public class SupportClass;
SupportClass Classes
Name

Description

ThreadSafeRandom (
37)

see page

Class to wrap static access to the random.Next (


a thread safe manner.

see page 37)() call in

SupportClass Methods
Name

Description

ByteArrayToString (
DeserializeData (

see page 37)

see page 37)

HashtableToString (

see page

see page 39)

WriteStackTrace (

Reversion function of SerializeData ( see page 39) to restore the


Hashtable ( see page 11) of serialized data.

see page 38) This method returns a string, representing the content of the given
hashtable. Returns null, if the parameter was null.

NumberToByteArray (
38)
SerializeData (

Converts a byte-array to string (for debuggin output).

see page 39)

Inserts the number's value into the byte array, using Big-Endian order
(a.k.a. Network-byte-order).
Uses the internal serialization methods to create a byte-array from the
data supplied.
Writes the exception's stack trace to the received stream.

36

3.1 Classes

Photon DotNet Client Documentation

SupportClass Class

3.1.5.1 SupportClass Classes


3.1.5.1.1 SupportClass.ThreadSafeRandom Class
Class to wrap static access to the random.Next (

see page 37)() call in a thread safe manner.

C#
public class ThreadSafeRandom;
ThreadSafeRandom Methods
Name
Next (

Description
see page 37)

This is Next, a member of class ThreadSafeRandom.

3.1.5.1.1.1 ThreadSafeRandom Methods


3.1.5.1.1.1.1 SupportClass.ThreadSafeRandom.Next Method
C#
public static int Next();
Description
This is Next, a member of class ThreadSafeRandom.

3.1.5.2 SupportClass Methods


3.1.5.2.1 SupportClass.ByteArrayToString Method
Converts a byte-array to string (for debuggin output).
C#
public static string ByteArrayToString(byte[] list);
Parameters
Parameters

Description

byte[] list

Byte-array to convert to string.

Returns
List of bytes as string (numbers separated by " ").

3.1.5.2.2 SupportClass.DeserializeData Method


Reversion function of SerializeData (

see page 39) to restore the Hashtable (

see page 11) of serialized data.

C#
public static Hashtable DeserializeData(byte[] dataBytes);
Parameters
Parameters

Description

byte[] dataBytes

A byte-array representing a Hashtable ( see page 11)


encoded with SerializeData ( see page 39).

37

3.1 Classes

Photon DotNet Client Documentation

SupportClass Class

Returns
The Hashtable (

see page 11) that went into SerializeData (

see page 39).

3.1.5.2.3 SupportClass.HashtableToString Method


This method returns a string, representing the content of the given hashtable. Returns null, if the parameter was null.
C#
public static string HashtableToString(Hashtable neutronEvent);
Parameters
Parameters

Description

Hashtable neutronEvent

_nt_

3.1.5.2.4 NumberToByteArray Method


3.1.5.2.4.1 SupportClass.NumberToByteArray Method (byte[], int, int)
Inserts the number's value into the byte array, using Big-Endian order (a.k.a. Network-byte-order).
C#
public static void NumberToByteArray(byte[] buffer, int index, int number);
Parameters
Parameters

Description

byte[] buffer

Byte array to write into.

int index

Index of first position to write to.

int number

Number to write.

3.1.5.2.4.2 SupportClass.NumberToByteArray Method (byte[], int, long)


Inserts the number's value into the byte array, using Big-Endian order (a.k.a. Network-byte-order).
C#
public static void NumberToByteArray(byte[] buffer, int index, long number);
Parameters
Parameters

Description

byte[] buffer

Byte array to write into.

int index

Index of first position to write to.

long number

Number to write.

3.1.5.2.4.3 SupportClass.NumberToByteArray Method (byte[], int, short)


Inserts the number's value into the byte array, using Big-Endian order (a.k.a. Network-byte-order).

C#
public static void NumberToByteArray(byte[] buffer, int index, short number);
Parameters
Parameters

Description

byte[] buffer

Byte array to write into.

int index

Index of first position to write to.

short number

Number to write.

38

3.2 Interfaces

Photon DotNet Client Documentation

IPhotonPeerListener Interface

3.1.5.2.5 SupportClass.SerializeData Method


Uses the internal serialization methods to create a byte-array from the data supplied.
C#
public static byte[] SerializeData(Hashtable data);
Parameters
Parameters

Description

Hashtable data

Data Hashtable (
byte-array.

see page 11) to be converted into a

Returns
Serialized data in form of a byte-array or null in case of error.
Remarks
This method can be helpful to save (almost) any data locally. The format uses a minimum of bytes for the given data.
You can put any information into the Hashtable (
Datatypes ( see page 5).

see page 11) as long as key and value are from the list of Serializable

See Also
DeserializeData (

see page 37)

3.1.5.2.6 SupportClass.WriteStackTrace Method


Writes the exception's stack trace to the received stream.
C#
public static void WriteStackTrace(System.Exception throwable, System.IO.TextWriter stream);
Parameters
Parameters

Description

System.Exception throwable

Exception to obtain information from.

System.IO.TextWriter stream

Output sream used to write to.

3.2 Interfaces
The following table lists interfaces in this documentation.
Interfaces
Name
IPhotonPeerListener (
39)

Description
see page

Callback interface for the Photon client side. Must be provided to a new
PhotonPeer ( see page 23) in its constructor.

3.2.1 IPhotonPeerListener Interface


Callback interface for the Photon client side. Must be provided to a new PhotonPeer (

see page 23) in its constructor.

C#
public interface IPhotonPeerListener;
39

3.2 Interfaces

Photon DotNet Client Documentation

IPhotonPeerListener Interface

Remarks
These methods are used by your PhotonPeer ( see page 23) instance to keep your app updated. Read each method's
description and check out the samples to see how to use them.
IPhotonPeerListener Methods
Name
DebugReturn (

EventAction (

Description
see page 40)

see page 40)

OperationResult (

see page 41)

PeerStatusCallback (
41)

see page

Provides textual descriptions for various error conditions and noteworthy


situations. In cases where the application needs to react, a call to
PeerStatusCallback ( see page 41) is used.
Called whenever an event from the Photon Server is Dispatched.
Sent operations may cause (asynchronous) calls to this method,
providing the result values of your Photon server.
PeerStatusCallback() is used to denote errors or simply state-changes of
the respective PhotonPeer ( see page 23).

3.2.1.1 IPhotonPeerListener Methods


3.2.1.1.1 IPhotonPeerListener.DebugReturn Method
Provides textual descriptions for various error conditions and noteworthy situations. In cases where the application needs to
react, a call to PeerStatusCallback ( see page 41) is used.
C#
void DebugReturn(DebugLevel level, string message);
Parameters
Parameters

Description

DebugLevel level

Debug level (severity) of the message.

string message

Debug text which usually is printed to System.Console.

Remarks
All debug output of the library will be reported through this method. Print it or put it in a buffer to use it on-screen. Use
PhotonPeer.DebugOut ( see page 32) to select how verbose the output is.

3.2.1.1.2 IPhotonPeerListener.EventAction Method


Called whenever an event from the Photon Server is Dispatched.
C#
void EventAction(byte eventCode, Hashtable photonEvent);
Parameters
Parameters

Description

byte eventCode

Defines the type of the dispatched event (and thus content


and meaning of it). Defined codes are in struct LiteEventKey
( see page 44).

Hashtable photonEvent

A Hashtable ( see page 11) with varying content,


depending on the eventCode.

Remarks
Events ( see page 3) are used for communication between clients. The creation of an event is most often triggered by an
operation call. There are predefined events ( see page 3) like EvJoin and EvLeave and some predefined event keys in the
LiteEventKey Structure ( see page 44). It is easy to create custom events ( see page 3) with LitePeer.OpRaiseEvent (
see page 20).
40

3.2 Interfaces

Photon DotNet Client Documentation

IPhotonPeerListener Interface

Events ( see page 3) are buffered on the client side and must be Dispatched. This way, EventAction is always taking place
in the same thread as a PhotonPeer.DispatchIncomingCommands ( see page 28) call.

3.2.1.1.3 IPhotonPeerListener.OperationResult Method


Sent operations may cause (asynchronous) calls to this method, providing the result values of your Photon server.
C#
void OperationResult(byte opCode, int returnCode, Hashtable returnValues, short invocID);
Parameters
Parameters

Description

byte opCode

OpCode of the operation.

int returnCode

Result of the operation in form of an integer return value.

Hashtable returnValues

Hashtable (
operation.

short invocID

Identification number of the operation-call.

see page 11) of returned values for the

Remarks
This method is used as general callback for all operations. The "type" of an operation is identified by a opCode (see:
Operations ( see page 2)).
The "Lite Application" uses these OpCodes:
LiteOpCode.Join (

see page 45) - as return for OpJoin(), contains the actorNr of "this" player

LiteOpCode.Leave (

see page 45) - as return for OpLeave()

LiteOpCode.RaiseEvent (

see page 45) - as return for OpRaiseEvent() (

see page 20) with reliable set to true

LiteOpCode.SetProperties ( see page 45) - as return for OpSetPropertiesOfActor() (


OpSetPropertiesOfGame() ( see page 22)

see page 22) and

An operation's result is summarized by the returnCode: an int typed code for "Ok" or one some error code. Compare the
returnCode to the values of enum ReturnCode.
The opCode defines the type of operation called on Photon and in turn also the returnValues. They are provided as
Hashtable ( see page 11) which contains the complete "answer" of Photon, including keys for opCode and returnCode.
Each operation returns its opCode and returnCode but anything else can be (re-)defined server-side.
Each call of an operation gets an ID, called the "invocID". This can be matched to the IDs returned with any operation calls.
This way, an application could track if a certain OpRaiseEvent call was successful.
Example
When you join a room, the server will assign a consecutive number to each client: the "actorNr" or "player number". This is
sent back in the returnValues as value of key LiteEventKey.ActorNr ( see page 44).
Fetch your actorNr in a Join-callback like this:
int actorNr = (int)neutronEvent[(byte)LiteEventKey.ActorNr];

3.2.1.1.4 IPhotonPeerListener.PeerStatusCallback Method


PeerStatusCallback() is used to denote errors or simply state-changes of the respective PhotonPeer (

3
see page 23).

C#
void PeerStatusCallback(StatusCode statusCode);
Parameters
Parameters

Description

StatusCode statusCode

_nt_
41

3.3 Structs, Records, Enums

Photon DotNet Client Documentation

ConnectionProtocol Enumeration

Remarks
State change callback
When this method is used to signalize a state-change, the opCode and other values will be 0 (or null) with the following
statusCode values:
StatusCode.Connect (

see page 48) - the connection to the Photon Server was established

StatusCode.Disconnect (

see page 48) - the connection was closed (due to Disconnect() (

StatusCode.Exception (

see page 48) - some system or network error closed the connection

see page 28) or timeout)

Possible errors
When developing with the Photon API, hundrets of events ( see page 3) might reach a client each minute. If they are not
processed in time, they might cause issues. As result of this, there are warnings and errors, which should help getting the
timing right. Check the StatusCode ( see page 48) for a list.

3.3 Structs, Records, Enums


The following table lists structs, records, enums in this documentation.
Enumerations
Name

Description

ConnectionProtocol (
DebugLevel (

LiteEventCode (

LiteEventKey (

LiteOpCode (

LiteOpKey (

see page 43) These are the options that can be used as transport protocol.

see page 43)


see page 43)

see page 44)

see page 45)

see page 45)

LitePropertyTypes (
PeerStateValue (

PhotonEventKey (

Lite - Event ( see page 3) codes. These codes are defined by the Lite
application's logic on the server side. Other application's won't
necessarily use these.
Lite - Keys of event-content that's defined in the Lite application logic. To
keep things lean (in terms of bandwidth), we use byte keys to identify
values in events ( see page 3) within Lite. In Lite, you can send custom
events ( see page 3). Their content can be of any type for key (and
value of course). Content of custom events ( see page 3) is in a
sub-hashtable under key LiteEventKey.Data.
Lite - Operation Codes. This enumeration contains the codes that are
given to the Lite Application's operations. Instead of sending "Join", this
enables us to send the byt 90.
Lite - Keys for operation-parameters and return-values (short: OpKey).
Keys for operation-parameters could be assigned on a per operation
basis, but it makes sense if certain values (which are used throughout the
whole application) have fixed keys. Client and server side could re-use
the same key for those.
The MMO application and any application that's started from scratch can
use their own keys, aside from ReturnCode = 0, DebugString = 1 and
Code = 60 (which are essential for the Photon Client at the time being).

see page 46)

see page 47)

Lite - Flags for "types of properties", being used as filter in


OpGetProperties.

Value range for a Peer's connection and initialization state, as returned


by the PeerState property. Check the description of each value for more
detail.

see page 47)

PhotonOpParameterKey (
page 48)
StatusCode (

Level / amount of debugReturn callbacks. Each debug level includes


output for lower ones: OFF, ERROR, WARNING, INFO, ALL.

see

see page 48)

StatusCodes are used in PeerStatusCallback to inform an application


about connection status changes and errors.
42

3.3 Structs, Records, Enums

Photon DotNet Client Documentation

LiteEventCode Enumeration

3.3.1 ConnectionProtocol Enumeration


These are the options that can be used as transport protocol.
C#
public enum ConnectionProtocol : byte {
Udp = 0,
Tcp = 1
}
Members
Members

Description

Udp = 0

Use reliable UDP to connect to Photon.

Tcp = 1

Use TCP to connect to Photon.

3.3.2 DebugLevel Enumeration


Level / amount of debugReturn callbacks. Each debug level includes output for lower ones: OFF, ERROR, WARNING,
INFO, ALL.
C#
public enum DebugLevel : byte {
OFF = 0,
ERROR = 1,
WARNING = 2,
INFO = 3,
ALL = 5
}
Members
Members

Description

OFF = 0

No debug out.

ERROR = 1

Only error descriptions.

WARNING = 2

Warnings and errors.

INFO = 3

Information about internal workflows, warnings and errors.

ALL = 5

Most complete workflow description (but lots of debug


output), info, warnings and errors.

3.3.3 LiteEventCode Enumeration


Lite - Event ( see page 3) codes. These codes are defined by the Lite application's logic on the server side. Other
application's won't necessarily use these.
C#
public enum LiteEventCode : int {
Join = 90,
Leave = 91,
SetProperties = 92
}

43

3.3 Structs, Records, Enums

Photon DotNet Client Documentation

LiteOpCode Enumeration

Members
Members

Description

Join = 90

Event (

see page 3) Join: someone joined the game

Leave = 91

Event (

see page 3) Leave: someone left the game

SetProperties = 92

Event (

see page 3) SetProperties

Remarks
If your game is built as extension of Lite, don't re-use these codes for your custom events (

see page 3).

3.3.4 LiteEventKey Enumeration


Lite - Keys of event-content that's defined in the Lite application logic. To keep things lean (in terms of bandwidth), we use
byte keys to identify values in events ( see page 3) within Lite. In Lite, you can send custom events ( see page 3). Their
content can be of any type for key (and value of course). Content of custom events ( see page 3) is in a sub-hashtable
under key LiteEventKey.Data.
C#
public enum LiteEventKey : byte {
ActorNr = 9,
TargetActorNr = 10,
ActorList = 11,
Properties = 12,
ActorProperties = 14,
GameProperties = 15,
Code = PhotonEventKey.Code,
Data = 42,
CustomEventContent = 42
}
Members
Members

Description

ActorNr = 9

Playernumber of the player who triggered the event.

TargetActorNr = 10

Playernumber of the player who is target of an event (e.g.


changed properties).

ActorList = 11

List of playernumbers currently in the room.

Properties = 12

Set of properties (a Hashtable (

ActorProperties = 14

Key for actor (player) property set (Hashtable (


11)).

see page

GameProperties = 15

Key for game (room) property set (Hashtable (


11)).

see page

Code = PhotonEventKey.Code

Event ( see page 3) Code (type of an event). Defines the


type of an event (why it's sent and what's in it).

Data = 42

Content of an event (a Hashtable (


likely).

CustomEventContent = 42

Content of custom events ( see page 3), which were


created by a client by calling OpRaiseEvent. Most likely the
value of this key is a Hashtable ( see page 11).

see page 11)).

see page 11) most

Remarks
If your game is built as extension of Lite, don't re-use these codes for your custom events (

see page 3).

44

3.3 Structs, Records, Enums

Photon DotNet Client Documentation

LiteOpKey Enumeration

3.3.5 LiteOpCode Enumeration


Lite - Operation Codes. This enumeration contains the codes that are given to the Lite Application's operations. Instead of
sending "Join", this enables us to send the byt 90.
C#
public enum LiteOpCode : byte {
Blank = 0,
Join = 90,
Leave = 91,
RaiseEvent = 92,
SetProperties = 93,
GetProperties = 94,
ExchangeKeysForEncryption = 95
}
Members
Members

Description

Blank = 0

No operation.

Join = 90

Code for OpJoin, to get into a room.

Leave = 91

Code for OpLeave, to get out of a room.

RaiseEvent = 92

Code for OpRaiseEvent (not same as eventCode).

SetProperties = 93

Code for OpSetProperties.

GetProperties = 94

Operation Code for OpGetProperties.

ExchangeKeysForEncryption = 95

Operation Code for OpGetProperties.

Remarks
Other applications (the MMO demo or your own) could define other operations and other codes. If your game is built as
extension of Lite, don't re-use these codes for your custom events ( see page 3).

3.3.6 LiteOpKey Enumeration


Lite - Keys for operation-parameters and return-values (short: OpKey). Keys for operation-parameters could be assigned on
a per operation basis, but it makes sense if certain values (which are used throughout the whole application) have fixed
keys. Client and server side could re-use the same key for those.
The MMO application and any application that's started from scratch can use their own keys, aside from ReturnCode = 0,
DebugString = 1 and Code = 60 (which are essential for the Photon Client at the time being).
C#
public enum LiteOpKey : byte {
ReturnCode = PhotonOpParameterKey.ReturnCode,
DebugString = PhotonOpParameterKey.DebugString,
Asid = 4,
RoomName = 4,
ActorNr = 9,
TargetActorNr = 10,
ActorList = 11,
Properties = 12,
Broadcast = 13,
ActorProperties = 14,
GameProperties = 15,
ClientKey = 16,
ServerKey = 17,
Code = PhotonOpParameterKey.Code,
Data = 42

45

3.3 Structs, Records, Enums

Photon DotNet Client Documentation

PeerStateValue Enumeration

}
Members
Members

Description

ReturnCode = PhotonOpParameterKey.ReturnCode

Key of the the ReturnCode for operations, which notifies of


success of failures.

DebugString = PhotonOpParameterKey.DebugString

Key of the debug string that's contained in any operation


result.

Asid = 4

Key of the room name. Used in OpJoin (Asid = Application


Session ID).

RoomName = 4

Key of the room name. Used in OpJoin.

ActorNr = 9

Key of the Actor of an operation. Used for property get and


set.

TargetActorNr = 10

Key of the target Actor of an operation. Used for property


set. Is 0 for game

ActorList = 11

Key for list of players in a room. Currently not used.

Properties = 12

Key for property set (Hashtable ( see page 11)). This key is
used when sending only one set of properties. If either
ActorProperties or GameProperties are used (of both), check
those keys.

Broadcast = 13

Key for broadcast parameter of OpSetProperties method.

ActorProperties = 14

Key for property set (Hashtable (

see page 11)).

GameProperties = 15

Key for property set (Hashtable (

see page 11)).

ClientKey = 16

Key for client's crypto public-key.

ServerKey = 17

Key for server's crypto public-key (used in a response).

Code = PhotonOpParameterKey.Code

Key of operation code. Used in all operations.

Data = 42

Key of data of an event. Used in OpRaiseEvent.

Remarks
These keys match a definition in the Lite application (part of the server SDK). If your game is built as extension of Lite, don't
re-use these codes for your custom events ( see page 3).

3.3.7 LitePropertyTypes Enumeration


Lite - Flags for "types of properties", being used as filter in OpGetProperties.
C#
[Flags]
public enum LitePropertyTypes : byte {
None = 0x00,
Game = 0x01,
Actor = 0x02,
GameAndActor = Game|Actor
}
Members
Members

Description

None = 0x00

Flag type for no property type.

Game = 0x01

Flag type for game-attached properties.

Actor = 0x02

Flag type for actor related propeties.

GameAndActor = Game|Actor

Flag type for game AND actor properties.

46

3.3 Structs, Records, Enums

Photon DotNet Client Documentation

PhotonOpParameterKey Enumeration

3.3.8 PeerStateValue Enumeration


Value range for a Peer's connection and initialization state, as returned by the PeerState property. Check the description of
each value for more detail.
C#
public enum PeerStateValue : byte {
Disconnected = 0,
Connecting = 1,
InitializingApplication = 10,
Connected = 3,
Disconnecting = 4
}
Members
Members

Description

Disconnected = 0

The peer is disconnected and can't call Operations (


page 2). Call Connect().

Connecting = 1

The peer is establishing the connection: opening a socket,


exchanging packages with Photon.

InitializingApplication = 10

The connection is established and now sends the application


name to Photon.

Connected = 3

The peer is connected and initialized (selected an


application). You can now use operations.

Disconnecting = 4

The peer is disconnecting. It sent a disconnect to the server,


which will acknowledge closing the connection.

see

Remarks
While this is not the same as the StatusCode ( see page 48) of IPhotonPeerListener.PeerStatusCallback ( see page
41)(), it directly relates to it. In most cases, it makes more sense to build a game's state on top of the PeerStatusCallback()
as you get changes.

3.3.9 PhotonEventKey Enumeration


C#
public enum PhotonEventKey : byte {
Code = 60
}
Members
Members

Description

Code = 60

Event ( see page 3) Code (type of an event). Defines the


type of an event (why it's sent and what's in it).

Remarks
Defined by Photon (cannot be re-assigned by any application).

47

3.3 Structs, Records, Enums

Photon DotNet Client Documentation

StatusCode Enumeration

3.3.10 PhotonOpParameterKey Enumeration


C#
public enum PhotonOpParameterKey : byte {
ReturnCode = 0,
DebugString = 1,
Code = 60
}
Members
Members

Description

ReturnCode = 0

Key of the the ReturnCode for operations, which notifies of


success of failures.

DebugString = 1

Key of the debug string that's contained in any operation


result.

Code = 60

Key of operation code. Used in all operations.

Remarks
Defined by Photon (cannot be re-assigned by any application).

3.3.11 StatusCode Enumeration


StatusCodes are used in PeerStatusCallback to inform an application about connection status changes and errors.
C#
public enum StatusCode : int {
Connect = 1024,
Disconnect = 1025,
Exception = 1026,
Exception_Connect = 1023,
SecurityExceptionOnConnect = 1022,
QueueOutgoingReliableWarning = 1027,
QueueOutgoingReliableError = 1028,
QueueOutgoingUnreliableWarning = 1029,
SendError = 1030,
QueueOutgoingAcksWarning = 1031,
QueueIncomingReliableWarning = 1033,
QueueIncomingUnreliableWarning = 1035,
QueueSentWarning = 1037,
InternalReceiveException = 1039,
TimeoutDisconnect = 1040,
DisconnectByServer = 1041,
DisconnectByServerUserLimit = 1042,
DisconnectByServerLogic = 1043
}
Members
Members

Description

Connect = 1024

the PhotonPeer ( see page 23) is connected.See {@link


PhotonListener#PeerStatusCallback}*

Disconnect = 1025

the PhotonPeer ( see page 23) just disconnected.See


{@link PhotonListener#PeerStatusCallback}*

Exception = 1026

the PhotonPeer ( see page 23) encountered an exception


and will disconnect, too.See {@link
PhotonListener#PeerStatusCallback}*

48

3.3 Structs, Records, Enums

Photon DotNet Client Documentation

StatusCode Enumeration

Exception_Connect = 1023

the PhotonPeer ( see page 23) encountered an exception


while opening the incoming connection to the server. The
server could be down / not running.See {@link
PhotonListener#PeerStatusCallback}*

QueueOutgoingReliableWarning = 1027

PhotonPeer ( see page 23) outgoing queue is filling up.


send more often.

QueueOutgoingReliableError = 1028

PhotonPeer ( see page 23) outgoing queue is filling up.


send more often.

QueueOutgoingUnreliableWarning = 1029

PhotonPeer ( see page 23) outgoing queue is filling up.


send more often.

SendError = 1030

Sending command failed. Either not connected, or the


requested channel is bigger than the number of initialized
channels.

QueueOutgoingAcksWarning = 1031

not yet used

QueueIncomingReliableWarning = 1033

PhotonPeer ( see page 23) incoming queue is filling up.


Dispatch more often.

QueueIncomingUnreliableWarning = 1035

PhotonPeer ( see page 23) incoming queue is filling up.


Dispatch more often.

QueueSentWarning = 1037

PhotonPeer ( see page 23) incoming queue is filling up.


Dispatch more often.

InternalReceiveException = 1039

Exception, if a server cannot be connected. Most likely, the


server is not responding. Ask user to try again later.

TimeoutDisconnect = 1040

Disconnection due to a timeout (client did no longer receive


ACKs from server).

DisconnectByServer = 1041

Disconnect by server due to timeout (received a disconnect


command, cause server misses ACKs of client).

DisconnectByServerUserLimit = 1042

Disconnect by server due to concurrent user limit reached


(received a disconnect command).

DisconnectByServerLogic = 1043

Disconnect by server due to server's logic (received a


disconnect command).

49

Photon DotNet Client Documentation

Index

DisconnectByServerLogic enumeration member 48


DisconnectByServerUserLimit enumeration member 48
Disconnected enumeration member 47

Disconnecting enumeration member 47

Actor enumeration member 46


ActorList enumeration member 44, 45

ActorNr enumeration member 44, 45

ERROR enumeration member 43

ActorProperties enumeration member 44, 45

Events 3

ALL enumeration member 43

Exception enumeration member 48

ArrayList 10

Exception_Connect enumeration member 48

ArrayList class 10

ExchangeKeysForEncryption enumeration member 45

about ArrayList class 10


ArrayList 11
Synchronized 11
SyncRoot 11

F
Fragmentation and Channels 3
Further Help 7

ArrayList.ArrayList 11
ArrayList.Synchronized 11
ArrayList.SyncRoot 11
Asid enumeration member 45

G
Game enumeration member 46
GameAndActor enumeration member 46

GameProperties enumeration member 44, 45


GetProperties enumeration member 45

Blank enumeration member 45


Broadcast enumeration member 45

Hashtable 11
Hashtable class 11

Classes 10

about Hashtable class 11

ClientKey enumeration member 45

Hashtable 12

Code enumeration member 44, 45, 47, 48

Synchronized 12

Connect enumeration member 48

this 12

Connected enumeration member 47


Connecting enumeration member 47
ConnectionProtocol 43
ConnectionProtocol enumeration 43
CustomEventContent enumeration member 44

D
Data enumeration member 44, 45
DebugLevel 43
DebugLevel enumeration 43
DebugString enumeration member 45, 48
Disconnect enumeration member 48

ToString 13
Hashtable.Hashtable 12
Hashtable.Synchronized 12
Hashtable.this 12
Hashtable.ToString 13

I
INFO enumeration member 43
InitializingApplication enumeration member 47
Interfaces 39
InternalReceiveException enumeration member 48
IPhotonPeerListener 39

DisconnectByServer enumeration member 48


a

Photon DotNet Client Documentation


IPhotonPeerListener interface 39

LitePeer.OpLeave 20

about IPhotonPeerListener interface 39

LitePeer.OpRaiseEvent 20, 21, 22

DebugReturn 40

LitePeer.OpSetPropertiesOfActor 22

EventAction 40

LitePeer.OpSetPropertiesOfGame 22

OperationResult 41

LitePropertyTypes 46

PeerStatusCallback 41

LitePropertyTypes enumeration 46

IPhotonPeerListener.DebugReturn 40
IPhotonPeerListener.EventAction 40

IPhotonPeerListener.OperationResult 41

None enumeration member 46

IPhotonPeerListener.PeerStatusCallback 41

OFF enumeration member 43

Join enumeration member 43, 45

Operations 2
Overview 1

L
Leave enumeration member 43, 45

Lite Application 6

PeerStateValue 47

LiteEventCode 43

PeerStateValue enumeration 47

LiteEventCode enumeration 43

Photon for Silverlight 8

LiteEventKey 44

Photon for Unity3D 8

LiteEventKey enumeration 44

Photon Workflow 1

LiteOpCode 45

PhotonEventKey 47

LiteOpCode enumeration 45

PhotonEventKey enumeration 47

LiteOpKey 45

PhotonOpParameterKey 48

LiteOpKey enumeration 45

PhotonOpParameterKey enumeration 48

LitePeer 13

PhotonPeer 23

LitePeer class 13

PhotonPeer class 23

about LitePeer class 13

about PhotonPeer class 23

LitePeer 16, 17

BytesIn 31

OpGetProperties 17

BytesOut 32

OpGetPropertiesOfActor 17, 18

ChannelCount 32

OpGetPropertiesOfGame 18

CommandBufferSize 32

OpJoin 19

Connect 27

OpLeave 20

DebugOut 32

OpRaiseEvent 20, 21, 22

debugTimeForDeriveSharedKey 32

OpSetPropertiesOfActor 22

debugTimeForDiffieHellman 32

OpSetPropertiesOfGame 22

DeriveSharedKey 28

LitePeer.LitePeer 16, 17

Disconnect 28

LitePeer.OpGetProperties 17

DisconnectTimeout 33

LitePeer.OpGetPropertiesOfActor 17, 18

DispatchIncomingCommands 28

LitePeer.OpGetPropertiesOfGame 18

FetchServerTimestamp 28

LitePeer.OpJoin 19

GetLocalMsTimestampDelegate 36
b

Photon DotNet Client Documentation


IsEncryptionAvailable 33

PhotonPeer.OpCustom 29, 30

Listener 33

PhotonPeer.OpExchangeKeysForEncryption 30

LocalMsTimestampDelegate 33

PhotonPeer.PeerID 33

LocalTimeInMilliSeconds 33

PhotonPeer.PeerState 34

OpCustom 29, 30

PhotonPeer.PhotonPeer 26, 27

OpExchangeKeysForEncryption 30

PhotonPeer.PhotonPort 27

PeerID 33

PhotonPeer.QueuedIncomingCommands 34

PeerState 34

PhotonPeer.QueuedOutgoingCommands 34

PhotonPeer 26, 27

PhotonPeer.RoundTripTime 34

PhotonPort 27

PhotonPeer.RoundTripTimeVariance 34

QueuedIncomingCommands 34

PhotonPeer.SendOutgoingCommands 30

QueuedOutgoingCommands 34

PhotonPeer.SentCountAllowance 34

RoundTripTime 34

PhotonPeer.ServerAddress 35

RoundTripTimeVariance 34

PhotonPeer.ServerTimeInMilliSeconds 35

SendOutgoingCommands 30

PhotonPeer.Service 31

SentCountAllowance 34

PhotonPeer.StopThread 31

ServerAddress 35

PhotonPeer.TimePingInterval 35

ServerTimeInMilliSeconds 35

PhotonPeer.UseCommandActionQueue 35

Service 31

PhotonPeer.UsedProtocol 36

StopThread 31

PhotonPeer.WarningSize 36

TimePingInterval 35

Properties enumeration member 44, 45

UseCommandActionQueue 35

Properties on Photon 6

UsedProtocol 36
WarningSize 36

PhotonPeer.BytesIn 31

QueueIncomingReliableWarning enumeration member 48

PhotonPeer.BytesOut 32

QueueIncomingUnreliableWarning enumeration member 48

PhotonPeer.ChannelCount 32

QueueOutgoingAcksWarning enumeration member 48

PhotonPeer.CommandBufferSize 32

QueueOutgoingReliableError enumeration member 48

PhotonPeer.Connect 27

QueueOutgoingReliableWarning enumeration member 48

PhotonPeer.DebugOut 32

QueueOutgoingUnreliableWarning enumeration member 48

PhotonPeer.debugTimeForDeriveSharedKey 32

QueueSentWarning enumeration member 48

PhotonPeer.debugTimeForDiffieHellman 32
PhotonPeer.DeriveSharedKey 28
PhotonPeer.Disconnect 28
PhotonPeer.DisconnectTimeout 33
PhotonPeer.DispatchIncomingCommands 28
PhotonPeer.FetchServerTimestamp 28
PhotonPeer.GetLocalMsTimestampDelegate 36
PhotonPeer.IsEncryptionAvailable 33

R
RaiseEvent enumeration member 45
ReturnCode enumeration member 45, 48
RoomName enumeration member 45

PhotonPeer.Listener 33

SecurityExceptionOnConnect enumeration member 48

PhotonPeer.LocalMsTimestampDelegate 33

SendError enumeration member 48

PhotonPeer.LocalTimeInMilliSeconds 33

Serializable Datatypes 5
ServerKey enumeration member 45
c

Photon DotNet Client Documentation


SetProperties enumeration member 43, 45
StatusCode 48
StatusCode enumeration 48
Structs, Records, Enums 42
SupportClass 36
SupportClass class 36
about SupportClass class 36
ByteArrayToString 37
DeserializeData 37
HashtableToString 38
NumberToByteArray 38
SerializeData 39
WriteStackTrace 39
SupportClass.ByteArrayToString 37
SupportClass.DeserializeData 37
SupportClass.HashtableToString 38
SupportClass.NumberToByteArray 38
SupportClass.SerializeData 39
SupportClass.ThreadSafeRandom 37
SupportClass.ThreadSafeRandom class 37
about SupportClass.ThreadSafeRandom class 37
Next 37
SupportClass.ThreadSafeRandom.Next 37
SupportClass.WriteStackTrace 39

T
TargetActorNr enumeration member 44, 45
Tcp enumeration member 43
The Photon Server 6
TimeoutDisconnect enumeration member 48

U
Udp enumeration member 43
Using TCP 4

W
WARNING enumeration member 43

You might also like