Photon Bolt Engine API 1.3

Public Member Functions | Static Public Member Functions | Public Attributes | Properties | List of all members
Photon.Bolt.BoltConnection Class Reference

The connection to a remote endpoint More...

Inheritance diagram for Photon.Bolt.BoltConnection:
Photon.Bolt.BoltObject

Public Member Functions

void Disconnect ()
 Disconnect this connection More...
 
void Disconnect (IProtocolToken token, UdpConnectionDisconnectReason disconnectReason=UdpConnectionDisconnectReason.Disconnected)
 Disconnect this connection with custom data More...
 
override bool Equals (object obj)
 Reference comparison between two connections More...
 
ExistsResult ExistsOnRemote (BoltEntity entity)
 
ExistsResult ExistsOnRemote (BoltEntity entity, bool allowMaybe)
 
void ForceSceneSync ()
 
override int GetHashCode ()
 A hash code for this connection More...
 
int GetSkippedUpdates (BoltEntity en)
 
bool ReceiveData (out byte[] data)
 Receives the data. More...
 
void SendData (byte[] data)
 Sends the data. More...
 
void SetCanReceiveEntities (bool v)
 
void SetStreamBandwidth (int bytesPerSecond)
 Set the max amount of data allowed per second More...
 
void StreamBytes (UdpChannelName channel, byte[] data)
 Send a binary stream of data to this connection More...
 
override string ToString ()
 The string representation of this connection More...
 

Static Public Member Functions

static implicit operator bool (BoltConnection cn)
 
static implicit operator bool (BoltObject obj)
 

Public Attributes

int PacketsLost => _packetLostCounter
 How many packets were registered as lost packets More...
 
int PacketsReceived => _packetsReceived
 How many packets were received by this connection More...
 
int PacketsSent => _packetCounter
 How many packets were sent to this connection More...
 

Properties

IProtocolToken AcceptToken [get, set]
 A data token that was passed by the server when accepting the connection More...
 
int BitsPerSecondIn [get]
 How many bits per second we are receiving in More...
 
int BitsPerSecondOut [get]
 How many bits per second we are sending out More...
 
PacketTypeStats CommandsStats [get]
 
uint ConnectionId [get]
 For the host this will be the ID of the client, an on the client it will show the ID of the client More...
 
UdpConnectionType ConnectionType [get]
 
IProtocolToken ConnectToken [get, set]
 The ConnectToken contains the token sent by the client when connecting to a game server. When you call BoltNetwork.Connect, BoltMatchmaking.JoinSession or BoltMatchmaking.JoinRandomSession with a Token, it can be accessed via this property More...
 
int DejitterFrames [get]
 The dejitter delay in number of frames More...
 
UdpKit.UdpConnectionDisconnectReason DisconnectReason [get]
 
IProtocolToken DisconnectToken [get, set]
 The DisconnectToken contains the token used when a Connection is shutdown, either by the remote client or by the game server. When calling BoltConnection.Disconnect with a Token, it can be accessed via this property. More...
 
PacketTypeStats EventsStats [get]
 
EntityList HasControlOf [get]
 
bool IsLoadingMap [get]
 Returns true if the remote computer on the other end of this connection is loading a map currently, otherwise false More...
 
float PingAliased [get]
 The round-trip time across the network, including processing delays and acks More...
 
float PingNetwork [get]
 The round-trip time on the network More...
 
UdpEndPoint RemoteEndPoint [get]
 Remote end point of this connection More...
 
int RemoteFrame [get]
 The estimated frame of the simulation running at the other end of this connection More...
 
EntityLookup ScopedTo [get]
 
EntityLookup SourceOf [get]
 
PacketTypeStats StatesStats [get]
 
object UserData [get, set]
 User assignable object which lets you pair arbitrary data with the connection More...
 

Detailed Description

The connection to a remote endpoint

Example: Accepting an incoming connection.

public override void ConnectRequest(UdpEndPoint endpoint) {
BoltNetwork.Accept(endPoint);
}

Member Function Documentation

◆ Disconnect() [1/2]

void Photon.Bolt.BoltConnection.Disconnect ( )
inline

Disconnect this connection

Example: Terminating all connections.

void DisconnectAll() {
foreach(var connection in BoltNetwork.connections) {
connection.Disconnect();
}
}

◆ Disconnect() [2/2]

void Photon.Bolt.BoltConnection.Disconnect ( IProtocolToken  token,
UdpConnectionDisconnectReason  disconnectReason = UdpConnectionDisconnectReason.Disconnected 
)
inline

Disconnect this connection with custom data

Parameters
tokenA data token
disconnectReasonSpecify the disconnect reason to shutdown this connection

Example: Terminating all connections with a custom error message.

void DisconnectAll(int errorCode, string errorMessage) {
ServerMessage msg = new ServerMessage(errorCode, errorMessage);
foreach(var connection in BoltNetwork.connections) {
connection.Disconnect(errorMessage);
}
}

◆ Equals()

override bool Photon.Bolt.BoltConnection.Equals ( object  obj)
inline

Reference comparison between two connections

Parameters
objThe object to compare

bool Compare(BoltConnection A, BoltConnection B) { return A.Equals(B); }

◆ ExistsOnRemote() [1/2]

ExistsResult Photon.Bolt.BoltConnection.ExistsOnRemote ( BoltEntity  entity)
inline

◆ ExistsOnRemote() [2/2]

ExistsResult Photon.Bolt.BoltConnection.ExistsOnRemote ( BoltEntity  entity,
bool  allowMaybe 
)
inline

◆ ForceSceneSync()

void Photon.Bolt.BoltConnection.ForceSceneSync ( )
inline

◆ GetHashCode()

override int Photon.Bolt.BoltConnection.GetHashCode ( )
inline

A hash code for this connection

◆ GetSkippedUpdates()

int Photon.Bolt.BoltConnection.GetSkippedUpdates ( BoltEntity  en)
inline

◆ operator bool() [1/2]

static implicit Photon.Bolt.BoltConnection.operator bool ( BoltConnection  cn)
inlinestatic

◆ operator bool() [2/2]

static implicit Photon.Bolt.BoltObject.operator bool ( BoltObject  obj)
inlinestaticinherited

◆ ReceiveData()

bool Photon.Bolt.BoltConnection.ReceiveData ( out byte[]  data)
inline

Receives the data.

Returns
true, if data was received, false otherwise.
Parameters
dataData.

◆ SendData()

void Photon.Bolt.BoltConnection.SendData ( byte[]  data)
inline

Sends the data.

Parameters
dataData.

◆ SetCanReceiveEntities()

void Photon.Bolt.BoltConnection.SetCanReceiveEntities ( bool  v)
inline

◆ SetStreamBandwidth()

void Photon.Bolt.BoltConnection.SetStreamBandwidth ( int  bytesPerSecond)
inline

Set the max amount of data allowed per second

Parameters
bytesPerSecondThe rate in bytes / sec

Example: Configuring the initial stream bandwidth of new connections to 20 kb/s.

public override void Connected(BoltConnection connection) {
connection.SetStreamBandwidth(1024 * 20);
}

◆ StreamBytes()

void Photon.Bolt.BoltConnection.StreamBytes ( UdpChannelName  channel,
byte[]  data 
)
inline

Send a binary stream of data to this connection

Parameters
channelThe channel to send on
dataThe binary data

Example: Sending the binary data of a custom icon texture to the server using a static reference to the "PlayerIcon" channel that was created inside a Channels class.

void SendCustomIcon(Texture2D myCustomIcon) {
byte[] data = myCustomIcon.EncodeToPNG();
BoltNetwork.server.StreamBytes(Channels.PlayerIcon, data);
}

◆ ToString()

override string Photon.Bolt.BoltConnection.ToString ( )
inline

The string representation of this connection

Example: Logging the address of new connections using the string representation.

public override void Connected(BoltConnection connection) {
ServerLog.instance.Write("New Connection:" + connection.ToString());
}

Member Data Documentation

◆ PacketsLost

int Photon.Bolt.BoltConnection.PacketsLost => _packetLostCounter

How many packets were registered as lost packets

◆ PacketsReceived

int Photon.Bolt.BoltConnection.PacketsReceived => _packetsReceived

How many packets were received by this connection

◆ PacketsSent

int Photon.Bolt.BoltConnection.PacketsSent => _packetCounter

How many packets were sent to this connection

Property Documentation

◆ AcceptToken

IProtocolToken Photon.Bolt.BoltConnection.AcceptToken
getset

A data token that was passed by the server when accepting the connection

Example: Using the AcceptToken to store connection settings.

public override void Disconnected(BoltConnection connection, IProtocolToken token) {
ConnectionSettings connSettings = (ConnectionSettings)token;
StartCoroutine(RemoveIfTimeout(connection, connSettings.maxTimeout));
}

◆ BitsPerSecondIn

int Photon.Bolt.BoltConnection.BitsPerSecondIn
get

How many bits per second we are receiving in

Example: Showing the ping and data flow in and out.

void OnGUI() {
if(BoltNetwork.isConnected && BoltNetwork.isClient) {
GUILayout.Label("Ping:" + BoltNetwork.server.PingNetwork;
GUILayout.Label("Bandwidth Out:" + BoltNetwork.server.BitsPerSecondOut);
GUILayout.Label("Bandwidth In:" + BoltNetwork.server.BitsPerSecondIn);
}
}

◆ BitsPerSecondOut

int Photon.Bolt.BoltConnection.BitsPerSecondOut
get

How many bits per second we are sending out

Example: Showing the ping and data flow in and out.

void OnGUI() {
if(BoltNetwork.isConnected && BoltNetwork.isClient) {
GUILayout.Label("Ping:" + BoltNetwork.server.pingNetwork;
GUILayout.Label("Bandwidth Out:" + BoltNetwork.server.bitsPerSecondIn);
GUILayout.Label("Bandwidth In:" + BoltNetwork.server.bitsPerSecondOut);
}
}

◆ CommandsStats

PacketTypeStats Photon.Bolt.BoltConnection.CommandsStats
get

◆ ConnectionId

uint Photon.Bolt.BoltConnection.ConnectionId
get

For the host this will be the ID of the client, an on the client it will show the ID of the client

Example: Getting a connection Id

uint getID()
{
if (BoltNetwork.isClient)
{
//my Id
return BoltNetwork.server.ConnectionId;
}
else
{
//Id of first client
return BoltNetwork.clients.First().ConnectionId;
}
}

◆ ConnectionType

UdpConnectionType Photon.Bolt.BoltConnection.ConnectionType
get

◆ ConnectToken

IProtocolToken Photon.Bolt.BoltConnection.ConnectToken
getset

The ConnectToken contains the token sent by the client when connecting to a game server. When you call BoltNetwork.Connect, BoltMatchmaking.JoinSession or BoltMatchmaking.JoinRandomSession with a Token, it can be accessed via this property

◆ DejitterFrames

int Photon.Bolt.BoltConnection.DejitterFrames
get

The dejitter delay in number of frames

Example: Showing the dejitter delay frames and ping.

void OnGUI() {
if(BoltNetwork.isConnected && BoltNetwork.isClient) {
GUILayout.Label("Ping:" + BoltNetwork.server.pingNetwork;
GUILayout.Label("Dejitter Delay:" + BoltNetwork.server.DejitterFrames;
}
}

◆ DisconnectReason

UdpKit.UdpConnectionDisconnectReason Photon.Bolt.BoltConnection.DisconnectReason
get

◆ DisconnectToken

IProtocolToken Photon.Bolt.BoltConnection.DisconnectToken
getset

The DisconnectToken contains the token used when a Connection is shutdown, either by the remote client or by the game server. When calling BoltConnection.Disconnect with a Token, it can be accessed via this property.

◆ EventsStats

PacketTypeStats Photon.Bolt.BoltConnection.EventsStats
get

◆ HasControlOf

EntityList Photon.Bolt.BoltConnection.HasControlOf
get

◆ IsLoadingMap

bool Photon.Bolt.BoltConnection.IsLoadingMap
get

Returns true if the remote computer on the other end of this connection is loading a map currently, otherwise false

Example: Removing a preloaded player entity from the game if they disconnect while loading.

public override void Disconnected(BoltConnection connection) {
if(connection.isLoadingMap) {
PlayerEntityList.instance.RemoveFor(connection);
}
}

◆ PingAliased

float Photon.Bolt.BoltConnection.PingAliased
get

The round-trip time across the network, including processing delays and acks

Example: Showing the difference between ping and aliased ping. Aliased ping will always be larger.

void OnGUI() {
if(BoltNetwork.isConnected && BoltNetwork.isClient) {
GUILayout.Label("Ping:" + BoltNetwork.server.PingNetwork;
GUILayout.Label("Ping (Aliased):" + BoltNetwork.server.PingAliased;
}
}

◆ PingNetwork

float Photon.Bolt.BoltConnection.PingNetwork
get

The round-trip time on the network

Example: Displaying the network ping when in debug mode.

void OnGUI() {
if(BoltNetwork.isConnected && BoltNetwork.isClient) {
GUILayout.Label("Ping:" + BoltNetwork.server.PingNetwork;
}
}

◆ RemoteEndPoint

UdpEndPoint Photon.Bolt.BoltConnection.RemoteEndPoint
get

Remote end point of this connection

Example: Logging the address of new connections

public override void Connected(BoltConnection connection) {
ServerLog.Write(string.Format("[{0}:{1}] New Connection", connection.remoteEndPoint.Address, connection.remoteEndPoint.Port);
}

◆ RemoteFrame

int Photon.Bolt.BoltConnection.RemoteFrame
get

The estimated frame of the simulation running at the other end of this connection

Example: Calculating the average frame difference of the client and server for all clients.

float EstimateFrameDiff() {
int count
float avg;
foreach(BoltConnection client in BoltNetwork.clients) {
count++;
avg += BoltNetwork.serverFrame - client.remoteFrame;
}
avg = avg / count;
return avg;
}

◆ ScopedTo

EntityLookup Photon.Bolt.BoltConnection.ScopedTo
get

◆ SourceOf

EntityLookup Photon.Bolt.BoltConnection.SourceOf
get

◆ StatesStats

PacketTypeStats Photon.Bolt.BoltConnection.StatesStats
get

◆ UserData

object Photon.Bolt.BoltConnection.UserData
getset

User assignable object which lets you pair arbitrary data with the connection

Example: Using a reference to the player entity in the UserData property.

public override void Disconnected(BoltConnection connection) {
BoltNetwork.Destroy((BoltEntity)connection.UserData);
}