Photon Server API Documentation v5.0RC1

Public Member Functions | Static Public Member Functions | Protected Member Functions | Properties | List of all members
Photon.SocketServer.ApplicationBase Class Referenceabstract

The base class for a Photon application. The main method to override is CreatePeer. See Setup for initialization recommendations. More...

Inheritance diagram for Photon.SocketServer.ApplicationBase:
Photon.Hive.HiveApplication Photon.LoadBalancing.GameServer.GameApplication Photon.LoadBalancing.MasterServer.MasterApplication Photon.NameServer.PhotonApp

Public Member Functions

void BroadCastEvent< TPeer > (IEventData eventData, IEnumerable< TPeer > peers, SendParameters sendParameters)
 Sends an event to a list of peers. This method serializes the data just once per protocol instead of once per peer. More...
 
bool ConnectToServerTcp (IPEndPoint remoteEndPoint, string applicationName, object state)
 Establishes a TCP connection between two Photon instances. CreateServerPeer is called once the connection is established. OnServerConnectionFailed is called if the connection fails.
More...
 
bool ConnectToServerTcp (IPEndPoint remoteEndPoint, string applicationName, object state, IRpcProtocol protocol)
 Establishes a TCP connection between two Photon instances. CreateServerPeer is called once the connection is established. OnServerConnectionFailed is called if the connection fails.
More...
 
bool ConnectToServerMuxTcp (IPEndPoint remoteEndPoint, string applicationName, object state)
 Establishes a logical, multiplexed TCP connection between two Photon instances. Multiple logical connections are sharing a single physical connection. CreateServerPeer is called once a logical connection is established. OnServerConnectionFailed is called if the logical connection fails. If a phyiscal connection exists when ConnectToServerMuxTcp is called, it is used; otherwise a physical connection is established. If the physical connection is aborted, all logical connections are aborted as well. More...
 
bool ConnectToServerUdp (IPEndPoint remoteEndPoint, string applicationName, object state, byte numChannels, short? mtu, Version clientVersion=null)
 Establishes an UDP connection between two Photon instances. CreateServerPeer is called once the connection is established. OnServerConnectionFailed is called if the connection fails. More...
 
bool ConnectToServerWebSocketHixie76 (IPEndPoint remoteEndPoint, string applicationName, object state, string origin)
 Establishes an WebSocket connection between two Photon instances, using the Hixie76 WebSocket protocol. CreateServerPeer is called once the connection is established. OnServerConnectionFailed is called if the connection fails. More...
 
bool ConnectToServerWebSocket (IPEndPoint remoteEndPoint, string applicationName, object state, WebSocketVersion webSocketVersion, IRpcProtocol protocol)
 Establishes an WebSocket connection between two Photon instances. CreateServerPeer is called once the connection is established. OnServerConnectionFailed is called if the connection fails. More...
 
bool ConnectToServerWebRTC (IPEndPoint remoteEndPoint, string applicationName, object state, IRpcProtocol protocol)
 
bool ConnectToServer (IPEndPoint remoteEndPoint, string applicationName, object state)
 This method overload is obsolete; use ConnectToServerTcp. More...
 
bool ConnectToServer (IPEndPoint remoteEndPoint, bool useMux, string applicationName, object state)
 This method overload is obsolete; use ConnectToServerMuxTcp. More...
 
bool ConnectToServer (IPEndPoint remoteEndPoint, string applicationName, object state, IRpcProtocol protocol)
 This method overload is obsolete; use ConnectToServerTcp. More...
 
bool ConnectToServer (IPEndPoint remoteEndPoint, string applicationName, object state, byte numChannels, short? mtu, Version clientVersion=null)
 This method overload is obsolete; use ConnectToServerUdp. More...
 
void BroadcastMessage< TPeer > (object message, IEnumerable< TPeer > peers, SendParameters sendParameters)
 
string[] ListenerList (out ListenerStatus[] status)
 
bool ListenerStart (string name)
 
bool ListenerStop (string name)
 
bool AddRestRequestHandler (string path, RestRequestHandler handler)
 
bool RemoveRestRequestHandler (string path)
 
void InitCorePerformanceCounters ()
 
void OnWebRTCConnectionEstablished (IPhotonWebRTCPeer peer, byte maxChannelCount, uint flags)
 
void OnWebRTCChannelConnected (IPhotonWebRTCPeer peer, object userData, byte channelId, ChannelType ChannelType, bool unordered, ushort priority, uint reliability, string label, string protocol)
 
virtual void OnWebRTCChannelDestroyed (IPhotonWebRTCPeer peer, object userData, byte channelId)
 
void OnOutboundWebRTCConnectionEstablished (IPhotonWebRTCPeer peer, object userData, byte maxChannelCount, uint flags)
 
void OnOutboundWebRTCConnectionFailed (object userData, uint errorCode)
 
IPhotonApplication OnStart (string instanceName, string applicationName, IPhotonApplicationSink sink, IControlListeners listenerControl, ILogToUnmanagedLog unmanagedLog, IPhotonApplicationsCounter applicationsCounter, string unmanagedLogDirectory)
 Called when the application is started. This method calls Setup. More...
 

Static Public Member Functions

static T GetConfigSectionAndValidate< T > (string path)
 

Protected Member Functions

 ApplicationBase (IConfiguration configuration)
 Initializes a new instance of the ApplicationBase class. More...
 
abstract PeerBase CreatePeer (InitRequest initRequest)
 This method is called by the IPhotonApplication.OnInit implementation of this class. The inheritor should return a PeerBase implementation. More...
 
virtual IFiber CreatePeerFiber (InitRequest request)
 
virtual object DecryptAuthToken (InitRequest initRequest, byte[] authToken, int offset, int length, out Dictionary< byte, object > encryptionData, out string errorMsg)
 
virtual void OnServerConnectionFailed (int errorCode, string errorMessage, object state)
 Invoked if a connection attempt to a server fails. More...
 
virtual void OnStopRequested ()
 Called when photon stops application domain More...
 
abstract void Setup ()
 This method is called when the current application has been started. The inheritor can setup log4net here and execute other initialization routines here. More...
 
abstract void TearDown ()
 This method is called when the current application is being stopped. The inheritor can execute cleanup routines here. More...
 

Properties

IConfiguration Configuration [get, protected set]
 Configuration loaded by descendants More...
 
static ApplicationBase Instance [get]
 Gets the application instance. More...
 
string ApplicationName [get]
 Gets the application name set in PhotonServer.config. More...
 
string ApplicationPath [get]
 Gets the application path set in PhotonServer.config. More...
 
string ApplicationRootPath [get]
 Gets the path of the application root path - base location of all applications. More...
 
string BinaryPath [get]
 Gets the path of the application binaries. More...
 
int PeerCount [get]
 Gets the number of peers currently connected to the application. More...
 
string PhotonInstanceName [get]
 Gets the name of the photon instance. More...
 
bool Running [get]
 Gets a value indicating whether the application is running (the time between Setup and OnStopRequested). More...
 
string HwId [get]
 
string UnmanagedLogPath [get]
 Gets the log path of Photon. More...
 
Version CoreVersion [get]
 Gets Photon Native Core version (PhotonSocketServer.exe). More...
 
Version SdkVersion [get]
 Gets Photon Managed Core version (SDK). More...
 
int EncrptionQueueLimit [get, set]
 
bool UseEncryptionQueue [get, set]
 

Detailed Description

The base class for a Photon application. The main method to override is CreatePeer. See Setup for initialization recommendations.

Constructor & Destructor Documentation

◆ ApplicationBase()

Photon.SocketServer.ApplicationBase.ApplicationBase ( IConfiguration  configuration)
inlineprotected

Initializes a new instance of the ApplicationBase class.

Member Function Documentation

◆ AddRestRequestHandler()

bool Photon.SocketServer.ApplicationBase.AddRestRequestHandler ( string  path,
RestRequestHandler  handler 
)
inline

◆ BroadCastEvent< TPeer >()

void Photon.SocketServer.ApplicationBase.BroadCastEvent< TPeer > ( IEventData  eventData,
IEnumerable< TPeer >  peers,
SendParameters  sendParameters 
)
inline

Sends an event to a list of peers. This method serializes the data just once per protocol instead of once per peer.

Template Parameters
TPeerA PeerBase subclass type.
Parameters
eventDataThe event to send.
peersThe peers to send the event to.
sendParametersThe send options.
Type Constraints
TPeer :PeerBase 

◆ BroadcastMessage< TPeer >()

void Photon.SocketServer.ApplicationBase.BroadcastMessage< TPeer > ( object  message,
IEnumerable< TPeer >  peers,
SendParameters  sendParameters 
)
inline
Type Constraints
TPeer :PeerBase 

◆ ConnectToServer() [1/4]

bool Photon.SocketServer.ApplicationBase.ConnectToServer ( IPEndPoint  remoteEndPoint,
bool  useMux,
string  applicationName,
object  state 
)
inline

This method overload is obsolete; use ConnectToServerMuxTcp.

◆ ConnectToServer() [2/4]

bool Photon.SocketServer.ApplicationBase.ConnectToServer ( IPEndPoint  remoteEndPoint,
string  applicationName,
object  state 
)
inline

This method overload is obsolete; use ConnectToServerTcp.

◆ ConnectToServer() [3/4]

bool Photon.SocketServer.ApplicationBase.ConnectToServer ( IPEndPoint  remoteEndPoint,
string  applicationName,
object  state,
byte  numChannels,
short?  mtu,
Version  clientVersion = null 
)
inline

This method overload is obsolete; use ConnectToServerUdp.

◆ ConnectToServer() [4/4]

bool Photon.SocketServer.ApplicationBase.ConnectToServer ( IPEndPoint  remoteEndPoint,
string  applicationName,
object  state,
IRpcProtocol  protocol 
)
inline

This method overload is obsolete; use ConnectToServerTcp.

◆ ConnectToServerMuxTcp()

bool Photon.SocketServer.ApplicationBase.ConnectToServerMuxTcp ( IPEndPoint  remoteEndPoint,
string  applicationName,
object  state 
)
inline

Establishes a logical, multiplexed TCP connection between two Photon instances. Multiple logical connections are sharing a single physical connection. CreateServerPeer is called once a logical connection is established. OnServerConnectionFailed is called if the logical connection fails. If a phyiscal connection exists when ConnectToServerMuxTcp is called, it is used; otherwise a physical connection is established. If the physical connection is aborted, all logical connections are aborted as well.

Parameters
remoteEndPointThe remote endpoint to connect to.
applicationNameThe application name to connect to.
stateA state object that is returned with the callback.
Returns
Returns true if outbound connections are allowed (if Running is true).

◆ ConnectToServerTcp() [1/2]

bool Photon.SocketServer.ApplicationBase.ConnectToServerTcp ( IPEndPoint  remoteEndPoint,
string  applicationName,
object  state 
)
inline

Establishes a TCP connection between two Photon instances. CreateServerPeer is called once the connection is established. OnServerConnectionFailed is called if the connection fails.

Parameters
remoteEndPointThe remote endpoint to connect to.
applicationNameThe application name to connect to.
stateA state object that is returned with the callback.
Returns
Returns true if outbound connections are allowed (if Running is true).

◆ ConnectToServerTcp() [2/2]

bool Photon.SocketServer.ApplicationBase.ConnectToServerTcp ( IPEndPoint  remoteEndPoint,
string  applicationName,
object  state,
IRpcProtocol  protocol 
)
inline

Establishes a TCP connection between two Photon instances. CreateServerPeer is called once the connection is established. OnServerConnectionFailed is called if the connection fails.

Parameters
remoteEndPointThe remote endpoint to connect to.
applicationNameThe application name to connect to.
stateA state object that is returned with the callback.
protocolThe IRpcProtocol used to serialze message data./>
Returns
Returns true if outbound connections are allowed (if Running is true).

◆ ConnectToServerUdp()

bool Photon.SocketServer.ApplicationBase.ConnectToServerUdp ( IPEndPoint  remoteEndPoint,
string  applicationName,
object  state,
byte  numChannels,
short?  mtu,
Version  clientVersion = null 
)
inline

Establishes an UDP connection between two Photon instances. CreateServerPeer is called once the connection is established. OnServerConnectionFailed is called if the connection fails.

Parameters
remoteEndPointThe remote endpoint to connect to.
applicationNameThe application name to connect to.
stateA state object that is returned with the callback.
numChannelsThe number of channels used by the connection. Channels are prioritized (the lower the channel number, the higher the priority)
mtuMaximum transfer unit - specifies the max data size of each UDP package (in bytes). Bigger packages will be fragmented. The default value is 1200.
Returns
Returns true if outbound connections are allowed (if Running is true).

◆ ConnectToServerWebRTC()

bool Photon.SocketServer.ApplicationBase.ConnectToServerWebRTC ( IPEndPoint  remoteEndPoint,
string  applicationName,
object  state,
IRpcProtocol  protocol 
)
inline

◆ ConnectToServerWebSocket()

bool Photon.SocketServer.ApplicationBase.ConnectToServerWebSocket ( IPEndPoint  remoteEndPoint,
string  applicationName,
object  state,
WebSocketVersion  webSocketVersion,
IRpcProtocol  protocol 
)
inline

Establishes an WebSocket connection between two Photon instances. CreateServerPeer is called once the connection is established. OnServerConnectionFailed is called if the connection fails.

Parameters
remoteEndPointThe remote endpoint to connect to.
applicationNameThe application name to connect to.
stateA state object that is returned with the callback.
webSocketVersionThe websocket protocol version (currently supported: RF6455 and HyBi10)
protocolThe protocol to serialize the message data.
Returns
Returns true if outbound connections are allowed (if Running is true).

◆ ConnectToServerWebSocketHixie76()

bool Photon.SocketServer.ApplicationBase.ConnectToServerWebSocketHixie76 ( IPEndPoint  remoteEndPoint,
string  applicationName,
object  state,
string  origin 
)
inline

Establishes an WebSocket connection between two Photon instances, using the Hixie76 WebSocket protocol. CreateServerPeer is called once the connection is established. OnServerConnectionFailed is called if the connection fails.

Parameters
remoteEndPointThe remote endpoint to connect to.
applicationNameThe application name to connect to.
stateA state object that is returned with the callback.
originThe origin of the request.
Returns
Returns true if outbound connections are allowed (if Running is true).

◆ CreatePeer()

abstract PeerBase Photon.SocketServer.ApplicationBase.CreatePeer ( InitRequest  initRequest)
protectedpure virtual

This method is called by the IPhotonApplication.OnInit implementation of this class. The inheritor should return a PeerBase implementation.

Parameters
initRequestThe initialization request.
Returns
A new instance of PeerBase or null.

Implemented in Photon.LoadBalancing.GameServer.GameApplication, Photon.LoadBalancing.MasterServer.MasterApplication, Photon.NameServer.PhotonApp, and Photon.Hive.HiveApplication.

◆ CreatePeerFiber()

virtual IFiber Photon.SocketServer.ApplicationBase.CreatePeerFiber ( InitRequest  request)
inlineprotectedvirtual

◆ DecryptAuthToken()

virtual object Photon.SocketServer.ApplicationBase.DecryptAuthToken ( InitRequest  initRequest,
byte[]  authToken,
int  offset,
int  length,
out Dictionary< byte, object >  encryptionData,
out string  errorMsg 
)
inlineprotectedvirtual

◆ GetConfigSectionAndValidate< T >()

static T Photon.SocketServer.ApplicationBase.GetConfigSectionAndValidate< T > ( string  path)
inlinestatic
Type Constraints
T :new 

◆ InitCorePerformanceCounters()

void Photon.SocketServer.ApplicationBase.InitCorePerformanceCounters ( )
inline

◆ ListenerList()

string [] Photon.SocketServer.ApplicationBase.ListenerList ( out ListenerStatus[]  status)
inline

◆ ListenerStart()

bool Photon.SocketServer.ApplicationBase.ListenerStart ( string  name)
inline

◆ ListenerStop()

bool Photon.SocketServer.ApplicationBase.ListenerStop ( string  name)
inline

◆ OnOutboundWebRTCConnectionEstablished()

void Photon.SocketServer.ApplicationBase.OnOutboundWebRTCConnectionEstablished ( IPhotonWebRTCPeer  peer,
object  userData,
byte  maxChannelCount,
uint  flags 
)
inline

◆ OnOutboundWebRTCConnectionFailed()

void Photon.SocketServer.ApplicationBase.OnOutboundWebRTCConnectionFailed ( object  userData,
uint  errorCode 
)
inline

◆ OnServerConnectionFailed()

virtual void Photon.SocketServer.ApplicationBase.OnServerConnectionFailed ( int  errorCode,
string  errorMessage,
object  state 
)
inlineprotectedvirtual

Invoked if a connection attempt to a server fails.

Parameters
errorCodeThe error code.
errorMessageThe error message.
stateThe state.

◆ OnStart()

IPhotonApplication Photon.SocketServer.ApplicationBase.OnStart ( string  instanceName,
string  applicationName,
IPhotonApplicationSink  sink,
IControlListeners  listenerControl,
ILogToUnmanagedLog  unmanagedLog,
IPhotonApplicationsCounter  applicationsCounter,
string  unmanagedLogDirectory 
)
inline

Called when the application is started. This method calls Setup.

Parameters
instanceNameThe name of the instance.
applicationNameName of the application.
sinkThe sink.
listenerControlThe photon listener controller
unmanagedLog
Parameters
applicationsCounterAn IPhotonApplicationsCounter instance used to read photon socket server unmanaged counters.
unmanagedLogDirectoryThe log path of Photon.
Returns
PhotonApplication object.

◆ OnStopRequested()

virtual void Photon.SocketServer.ApplicationBase.OnStopRequested ( )
inlineprotectedvirtual

Called when photon stops application domain

Reimplemented in Photon.LoadBalancing.GameServer.GameApplication, and Photon.LoadBalancing.MasterServer.MasterApplication.

◆ OnWebRTCChannelConnected()

void Photon.SocketServer.ApplicationBase.OnWebRTCChannelConnected ( IPhotonWebRTCPeer  peer,
object  userData,
byte  channelId,
ChannelType  ChannelType,
bool  unordered,
ushort  priority,
uint  reliability,
string  label,
string  protocol 
)
inline

◆ OnWebRTCChannelDestroyed()

virtual void Photon.SocketServer.ApplicationBase.OnWebRTCChannelDestroyed ( IPhotonWebRTCPeer  peer,
object  userData,
byte  channelId 
)
inlinevirtual

◆ OnWebRTCConnectionEstablished()

void Photon.SocketServer.ApplicationBase.OnWebRTCConnectionEstablished ( IPhotonWebRTCPeer  peer,
byte  maxChannelCount,
uint  flags 
)
inline

◆ RemoveRestRequestHandler()

bool Photon.SocketServer.ApplicationBase.RemoveRestRequestHandler ( string  path)
inline

◆ Setup()

abstract void Photon.SocketServer.ApplicationBase.Setup ( )
protectedpure virtual

This method is called when the current application has been started. The inheritor can setup log4net here and execute other initialization routines here.

log4net initialization:

private static readonly ILogger log = LogManager.GetCurrentClassLogger();
protected override void Setup()
{
// configure log4net with a config file
var configFileInfo = new FileInfo(Path.Combine(this.BinaryPath, "log4net.config"));
XmlConfigurator.ConfigureAndWatch(configFileInfo);
// redirect photon sdk internal logging to log4net
}

Implemented in Photon.LoadBalancing.GameServer.GameApplication, Photon.LoadBalancing.MasterServer.MasterApplication, Photon.NameServer.PhotonApp, and Photon.Hive.HiveApplication.

◆ TearDown()

abstract void Photon.SocketServer.ApplicationBase.TearDown ( )
protectedpure virtual

This method is called when the current application is being stopped. The inheritor can execute cleanup routines here.

Implemented in Photon.LoadBalancing.GameServer.GameApplication, Photon.LoadBalancing.MasterServer.MasterApplication, Photon.NameServer.PhotonApp, and Photon.Hive.HiveApplication.

Property Documentation

◆ ApplicationName

string Photon.SocketServer.ApplicationBase.ApplicationName
get

Gets the application name set in PhotonServer.config.

◆ ApplicationPath

string Photon.SocketServer.ApplicationBase.ApplicationPath
get

Gets the application path set in PhotonServer.config.

◆ ApplicationRootPath

string Photon.SocketServer.ApplicationBase.ApplicationRootPath
get

Gets the path of the application root path - base location of all applications.

◆ BinaryPath

string Photon.SocketServer.ApplicationBase.BinaryPath
get

Gets the path of the application binaries.

◆ Configuration

IConfiguration Photon.SocketServer.ApplicationBase.Configuration
getprotected set

Configuration loaded by descendants

◆ CoreVersion

Version Photon.SocketServer.ApplicationBase.CoreVersion
get

Gets Photon Native Core version (PhotonSocketServer.exe).

◆ EncrptionQueueLimit

int Photon.SocketServer.ApplicationBase.EncrptionQueueLimit
getset

◆ HwId

string Photon.SocketServer.ApplicationBase.HwId
get

◆ Instance

ApplicationBase Photon.SocketServer.ApplicationBase.Instance
staticget

Gets the application instance.

◆ PeerCount

int Photon.SocketServer.ApplicationBase.PeerCount
get

Gets the number of peers currently connected to the application.

The peer count.

◆ PhotonInstanceName

string Photon.SocketServer.ApplicationBase.PhotonInstanceName
get

Gets the name of the photon instance.

◆ Running

bool Photon.SocketServer.ApplicationBase.Running
get

Gets a value indicating whether the application is running (the time between Setup and OnStopRequested).

◆ SdkVersion

Version Photon.SocketServer.ApplicationBase.SdkVersion
get

Gets Photon Managed Core version (SDK).

◆ UnmanagedLogPath

string Photon.SocketServer.ApplicationBase.UnmanagedLogPath
get

Gets the log path of Photon.

◆ UseEncryptionQueue

bool Photon.SocketServer.ApplicationBase.UseEncryptionQueue
getset
ExitGames.Logging
Definition: ILogger.cs:10
ExitGames.Logging.LogManager.SetLoggerFactory
static void SetLoggerFactory(ILoggerFactory factory)
Assigns a new ILoggerFactory to create ILogger instances.
Definition: LogManager.cs:110
ExitGames.Logging.Log4Net
Definition: Log4NetLogger.cs:10
ExitGames.Logging.LogManager
The log manager provides methods to get instances of ILogger using a ILoggerFactory....
Definition: LogManager.cs:25
ExitGames.Logging.Log4Net.ILogger
ILogger ILogger
Definition: Log4NetLogger.cs:16
ExitGames.Logging.Log4Net.Log4NetLoggerFactory.Instance
static readonly Log4NetLoggerFactory Instance
The singleton.
Definition: Log4NetLoggerFactory.cs:25
Photon.SocketServer.ApplicationBase.Setup
abstract void Setup()
This method is called when the current application has been started. The inheritor can setup log4net ...
ExitGames
Definition: BaseSubscription.cs:1
ExitGames.Logging.Log4Net.Log4NetLoggerFactory
This ILoggerFactory creates ILogger that log to the log4net framework.
Definition: Log4NetLoggerFactory.cs:20