Photon Server API

Classes | Public Member Functions | Protected Member Functions | Properties | List of all members
Photon.SocketServer.PeerBase Class Referenceabstract

This class is a base class for server connections. The RequestFiber processes all incoming messages. More...

Inheritance diagram for Photon.SocketServer.PeerBase:
Photon.LoadBalancing.LoadShedding.LatencyPeer Photon.SocketServer.ClientPeer Photon.SocketServer.ServerToServer.S2SPeerBase Photon.Hive.HivePeer Photon.LoadBalancing.MasterServer.RedirectedClientPeer Photon.SocketServer.Rpc.Peer Photon.LoadBalancing.LoadShedding.LatencyMonitor Photon.SocketServer.ServerToServer.InboundS2SPeer Photon.SocketServer.ServerToServer.OutboundS2SPeer Photon.Hive.Tests.TestHivePeer Photon.LoadBalancing.GameServer.GameClientPeer Photon.LoadBalancing.MasterServer.MasterClientPeer Photon.MmoDemo.Server.MmoPeer Photon.LoadBalancing.MasterServer.GameServer.IncomingGameServerPeer Photon.LoadBalancing.GameServer.OutgoingMasterServerPeer

Public Member Functions

void Initialize (InitRequest initRequest)
 
override string ToString ()
 
void Disconnect ()
 Closes the connection. More...
 
void AbortConnection ()
 Forces the connection to close immediately. Should only be used if "Disconnect" does not lead to a clean connection shutdown, e.g. in case of an overloaded connection. More...
 
void Flush ()
 Flushes all pending data to the socket. More...
 
byte[] InitializeEncryption (byte[] otherPartyPublicKey)
 Initializes the peer to receive and send encrypted operations with EncryptionMethod.Sha256Pkcs7. More...
 
byte[] InitializeEncryption (byte[] otherPartyPublicKey, EncryptionMethod mode)
 Initializes the peer to receive and send encrypted operations. More...
 
SendResult SendEvent (IEventData eventData, SendParameters sendParameters)
 Sends an IEventData object to the client. More...
 
SendResult SendMessage (object message, SendParameters sendParameters)
 
SendResult SendOperationResponse (OperationResponse operationResponse, SendParameters sendParameters)
 Sends the operation response to the client. More...
 
void GetStats (out int roundTripTime, out int roundTripTimeVariance, out int numFailures)
 
void SetDebugString (string message)
 
int GetLastTouch ()
 
void SetPrivateCustomTypeCache (CustomTypeCache cache)
 Sets private custom type cache. It is supposed to be used together with plugins. In other case Proptocol.TryRegisterCustomType should be used More...
 
void Dispose ()
 Disposes the peer. More...
 

Protected Member Functions

void Trace (bool enabled, object tag)
 
virtual SendResult SendData (byte[] data, SendParameters sendParameters)
 Sends bytes to the client. More...
 
virtual void OnReceive (byte[] data, SendParameters sendParameters)
 Invoked if incoming data was received for the peer. More...
 
virtual void Dispose (bool disposing)
 Disposes the internal fibers. More...
 
abstract void OnDisconnect (DisconnectReason reasonCode, string reasonDetail)
 The connection was closed. More...
 
virtual void OnSendBufferEmpty ()
 The default behavior of OnSendBufferFull is to disconnect the client. If this behavior is changed (override) the inheritor can pause sending until OnSendBufferEmpty is called. More...
 
virtual void OnUnexpectedDataReceived (byte[] data, string debugMessage)
 This method is called if incoming data has an unexpected format. Per default this method disconnects the client. Override to change this behavior. More...
 

Properties

ConnectionState ConnectionState [get, set]
 Gets the ConnectionState for this instance. More...
 
bool Connected [get]
 Gets a value indicating whether this PeerBase instance is connected. More...
 
int ConnectionId [get]
 Gets the connection id. More...
 
bool Disposed [get]
 Gets a value indicating whether the peer was disposed. More...
 
string LocalIP [get]
 Gets the IP the client connects to. More...
 
IPAddress? LocalIPAddress [get]
 Gets the IP Address the client connects to. More...
 
int LocalPort [get]
 Gets the port the client connects to. More...
 
NetworkProtocolType NetworkProtocol [get]
 Gets the network protocol type used by the peer. More...
 
IRpcProtocol Protocol [get, set]
 Gets the used IRpcProtocol protocol. More...
 
string RemoteIP [get]
 Gets the client's remote IP address. More...
 
IPAddress? RemoteIPAddress [get]
 Gets the client's remote IP address. More...
 
int RemotePort [get]
 Gets the port the client connects from. More...
 
IFiber RequestFiber [get]
 Gets fiber for incoming messages. More...
 
int RoundTripTime [get, protected set]
 Gets the last round trip time for this peer. More...
 
int RoundTripTimeVariance [get, protected set]
 Gets the last round trip time variance for this peer. More...
 
int NumFailures [get, protected set]
 
bool LocalIPAddressIsIPv6 [get]
 If true connection is using a server IPv6 endpoint. More...
 
bool SourceUsingIPv6 [get]
 If true the peer is using IPv6 to connect to the server, if the server enpoint used is not IPv6 (LocalIPAddressIsIPv6) it means the client is beeing bridged (DNS64+NAT64), also IsIPv6ToIPv4Bridged. More...
 
bool IsIPv6ToIPv4Bridged [get]
 If true the client is beeing bridged (DNS64+NAT64), also SourceUsingIPv6. More...
 

Detailed Description

This class is a base class for server connections. The RequestFiber processes all incoming messages.

Member Function Documentation

◆ AbortConnection()

void Photon.SocketServer.PeerBase.AbortConnection ( )
inline

Forces the connection to close immediately. Should only be used if "Disconnect" does not lead to a clean connection shutdown, e.g. in case of an overloaded connection.

◆ Disconnect()

void Photon.SocketServer.PeerBase.Disconnect ( )
inline

Closes the connection.

◆ Dispose() [1/2]

void Photon.SocketServer.PeerBase.Dispose ( )
inline

Disposes the peer.

◆ Dispose() [2/2]

virtual void Photon.SocketServer.PeerBase.Dispose ( bool  disposing)
inlineprotectedvirtual

Disposes the internal fibers.

Parameters
disposingTrue if called from Dispose().

Reimplemented in Photon.LoadBalancing.LoadShedding.LatencyMonitor, and Photon.MmoDemo.Server.MmoPeer.

◆ Flush()

void Photon.SocketServer.PeerBase.Flush ( )
inline

Flushes all pending data to the socket.

◆ GetLastTouch()

int Photon.SocketServer.PeerBase.GetLastTouch ( )
inline

◆ GetStats()

void Photon.SocketServer.PeerBase.GetStats ( out int  roundTripTime,
out int  roundTripTimeVariance,
out int  numFailures 
)
inline

◆ Initialize()

void Photon.SocketServer.PeerBase.Initialize ( InitRequest  initRequest)
inline

◆ InitializeEncryption() [1/2]

byte [] Photon.SocketServer.PeerBase.InitializeEncryption ( byte[]  otherPartyPublicKey)
inline

Initializes the peer to receive and send encrypted operations with EncryptionMethod.Sha256Pkcs7.

Parameters
otherPartyPublicKeyThe other party public key.
Returns
A byte array containing the public key of the created CryptoProvider instance. The key should be used to initialize cryptography operations on the client site.

◆ InitializeEncryption() [2/2]

byte [] Photon.SocketServer.PeerBase.InitializeEncryption ( byte[]  otherPartyPublicKey,
EncryptionMethod  mode 
)
inline

Initializes the peer to receive and send encrypted operations.

Parameters
otherPartyPublicKeyThe other party public key.
modeSpecifies the EncryptionMethod.
Returns
A byte array containing the public key of the created CryptoProvider instance. The key should be used to initialize cryptography operations on the client site.

◆ OnDisconnect()

abstract void Photon.SocketServer.PeerBase.OnDisconnect ( DisconnectReason  reasonCode,
string  reasonDetail 
)
protectedpure virtual

◆ OnReceive()

virtual void Photon.SocketServer.PeerBase.OnReceive ( byte[]  data,
SendParameters  sendParameters 
)
inlineprotectedvirtual

Invoked if incoming data was received for the peer.

Parameters
dataAn array of type Byte containing the received data.
sendParametersA SendParameters instance specifying how the data was send.

Can be overridden in a derived class to implement a custom request handling. The default implementation tries to parse the data as an OperationRequest and invokes the OnOperationRequest method of this instance.

Reimplemented in Photon.SocketServer.ServerToServer.S2SPeerBase.

◆ OnSendBufferEmpty()

virtual void Photon.SocketServer.PeerBase.OnSendBufferEmpty ( )
inlineprotectedvirtual

The default behavior of OnSendBufferFull is to disconnect the client. If this behavior is changed (override) the inheritor can pause sending until OnSendBufferEmpty is called.

◆ OnUnexpectedDataReceived()

virtual void Photon.SocketServer.PeerBase.OnUnexpectedDataReceived ( byte[]  data,
string  debugMessage 
)
inlineprotectedvirtual

This method is called if incoming data has an unexpected format. Per default this method disconnects the client. Override to change this behavior.

Parameters
dataThe received data.
debugMessageA debug message that specifies why the data was unexpected.

◆ SendData()

virtual SendResult Photon.SocketServer.PeerBase.SendData ( byte[]  data,
SendParameters  sendParameters 
)
inlineprotectedvirtual

Sends bytes to the client.

Parameters
dataThe data.
sendParametersThe send Options.
Returns
SendResult.Disconnected: Not connected anymore. SendResult.SendBufferFull: The send buffer was full. SendResult.Ok: Success.

◆ SendEvent()

SendResult Photon.SocketServer.PeerBase.SendEvent ( IEventData  eventData,
SendParameters  sendParameters 
)
inline

Sends an IEventData object to the client.

Parameters
eventDataThe event data.
sendParametersThe send Options.
Returns
SendResult.EncryptionNotSupported: Encryption not initialized. SendResult.Disconnected: Not connected anymore. SendResult.SendBufferFull: The send buffer was full. SendResult.Ok: Success.

◆ SendMessage()

SendResult Photon.SocketServer.PeerBase.SendMessage ( object  message,
SendParameters  sendParameters 
)
inline

◆ SendOperationResponse()

SendResult Photon.SocketServer.PeerBase.SendOperationResponse ( OperationResponse  operationResponse,
SendParameters  sendParameters 
)
inline

Sends the operation response to the client.

Parameters
operationResponseThe operation response.
sendParametersThe send Options.
Returns
SendResult.EncryptionNotSupported: Encryption not initialized. SendResult.Disconnected: Not connected. SendResult.SendBufferFull: The send buffer is full. SendResult.Ok: success.

◆ SetDebugString()

void Photon.SocketServer.PeerBase.SetDebugString ( string  message)
inline

◆ SetPrivateCustomTypeCache()

void Photon.SocketServer.PeerBase.SetPrivateCustomTypeCache ( CustomTypeCache  cache)
inline

Sets private custom type cache. It is supposed to be used together with plugins. In other case Proptocol.TryRegisterCustomType should be used

Parameters
cache

◆ ToString()

override string Photon.SocketServer.PeerBase.ToString ( )
inline

◆ Trace()

void Photon.SocketServer.PeerBase.Trace ( bool  enabled,
object  tag 
)
inlineprotected

Property Documentation

◆ Connected

bool Photon.SocketServer.PeerBase.Connected
get

Gets a value indicating whether this PeerBase instance is connected.

true if connected; otherwise, false.

◆ ConnectionId

int Photon.SocketServer.PeerBase.ConnectionId
get

Gets the connection id.

Peers connected to different ports may have similar connection ids.

◆ ConnectionState

ConnectionState Photon.SocketServer.PeerBase.ConnectionState
getset

Gets the ConnectionState for this instance.

◆ Disposed

bool Photon.SocketServer.PeerBase.Disposed
get

Gets a value indicating whether the peer was disposed.

The peer is automatically disposed after OnDisconnect.

◆ IsIPv6ToIPv4Bridged

bool Photon.SocketServer.PeerBase.IsIPv6ToIPv4Bridged
get

If true the client is beeing bridged (DNS64+NAT64), also SourceUsingIPv6.

◆ LocalIP

string Photon.SocketServer.PeerBase.LocalIP
get

Gets the IP the client connects to.

◆ LocalIPAddress

IPAddress? Photon.SocketServer.PeerBase.LocalIPAddress
get

Gets the IP Address the client connects to.

◆ LocalIPAddressIsIPv6

bool Photon.SocketServer.PeerBase.LocalIPAddressIsIPv6
get

If true connection is using a server IPv6 endpoint.

◆ LocalPort

int Photon.SocketServer.PeerBase.LocalPort
get

Gets the port the client connects to.

◆ NetworkProtocol

NetworkProtocolType Photon.SocketServer.PeerBase.NetworkProtocol
get

Gets the network protocol type used by the peer.

The network protocol type.

◆ NumFailures

int Photon.SocketServer.PeerBase.NumFailures
getprotected set

◆ Protocol

IRpcProtocol Photon.SocketServer.PeerBase.Protocol
getset

Gets the used IRpcProtocol protocol.

◆ RemoteIP

string Photon.SocketServer.PeerBase.RemoteIP
get

Gets the client's remote IP address.

◆ RemoteIPAddress

IPAddress? Photon.SocketServer.PeerBase.RemoteIPAddress
get

Gets the client's remote IP address.

◆ RemotePort

int Photon.SocketServer.PeerBase.RemotePort
get

Gets the port the client connects from.

◆ RequestFiber

IFiber Photon.SocketServer.PeerBase.RequestFiber
get

Gets fiber for incoming messages.

◆ RoundTripTime

int Photon.SocketServer.PeerBase.RoundTripTime
getprotected set

Gets the last round trip time for this peer.

This property is updated after each incoming request from the client. Only set for ENet / UDP peers, not for TCP peers.

◆ RoundTripTimeVariance

int Photon.SocketServer.PeerBase.RoundTripTimeVariance
getprotected set

Gets the last round trip time variance for this peer.

This property is updated after each incoming request from the client. Only set for ENet / UDP peers, not for TCP peers.

◆ SourceUsingIPv6

bool Photon.SocketServer.PeerBase.SourceUsingIPv6
get

If true the peer is using IPv6 to connect to the server, if the server enpoint used is not IPv6 (LocalIPAddressIsIPv6) it means the client is beeing bridged (DNS64+NAT64), also IsIPv6ToIPv4Bridged.