Photon Bolt Engine API  1.2.7
Public Member Functions | Static Public Member Functions | Properties | Private Member Functions | Private Attributes | List of all members
BoltConnection Class Reference

The connection to a remote endpoint More...

Inheritance diagram for BoltConnection:
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)
 
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 (BoltObject obj)
 
static implicit operator bool (BoltConnection cn)
 

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...
 
IProtocolToken ConnectToken [get, set]
 
int DejitterFrames [get]
 The dejitter delay in number of frames More...
 
UdpKit.UdpConnectionDisconnectReason DisconnectReason [get]
 
IProtocolToken DisconnectToken [get, set]
 
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...
 
object IBoltListNode< BoltConnection >. list [get, set]
 
BoltConnection IBoltListNode< BoltConnection >. next [get, set]
 
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...
 
BoltConnection IBoltListNode< BoltConnection >. prev [get, set]
 
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...
 
internal int remoteFrameDiff [get]
 
internal int remoteFrameLatest [get]
 
EntityLookup ScopedTo [get]
 
internal int SendRateMultiplier [get]
 
EntityLookup SourceOf [get]
 
PacketTypeStats StatesStats [get]
 
internal UdpConnection udpConnection [get]
 
object UserData [get, set]
 User assignable object which lets you pair arbitrary data with the connection More...
 

Private Member Functions

internal void AdjustRemoteFrame ()
 
internal BoltConnection (UdpConnection udpConnection)
 
internal void DisconnectedInternal ()
 
internal void PacketDelivered (Packet packet)
 
internal void PacketLost (Packet packet)
 
internal void PacketReceived (UdpPacket udpPacket)
 
internal void Send ()
 
internal bool StepRemoteEntities ()
 
internal void SwitchPerfCounters ()
 

Private Attributes

internal BinaryDataChannel _binaryDataChannel
 
int _bitsSecondIn
 
int _bitsSecondInAcc
 
int _bitsSecondOut
 
int _bitsSecondOutAcc
 
internal bool _canReceiveEntities = true
 
BoltChannel [] _channels
 
internal EntityChannel.CommandChannel _commandChannel
 
internal PacketTypeStats _commandStats
 
internal List< Entity > _controlling
 
internal EntityList _controllingList
 
internal EntityChannel _entityChannel
 
internal EventChannel _eventChannel
 
internal PacketTypeStats _eventsStats
 
int _framesToStep
 
int _packetCounter
 
int _packetsReceived
 
internal BoltRingBuffer< PacketStats_packetStatsIn
 
internal BoltRingBuffer< PacketStats_packetStatsOut
 
int _remoteFrameActual
 
bool _remoteFrameAdjust
 
int _remoteFrameDiff
 
int _remoteFrameEstimated
 
internal SceneLoadState _remoteSceneLoading
 
internal SceneLoadChannel _sceneLoadChannel
 
internal PacketTypeStats _stateStats
 
UdpConnection _udpConnection
 

Detailed Description

The connection to a remote endpoint

Example: Accepting an incoming connection.

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

Constructor & Destructor Documentation

◆ BoltConnection()

internal BoltConnection.BoltConnection ( UdpConnection  udpConnection)
inlineprivate

Member Function Documentation

◆ AdjustRemoteFrame()

internal void BoltConnection.AdjustRemoteFrame ( )
inlineprivate

◆ Disconnect() [1/2]

void BoltConnection.Disconnect ( )
inline

Disconnect this connection

Example: Terminating all connections.

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

◆ Disconnect() [2/2]

void 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);
}
}

◆ DisconnectedInternal()

internal void BoltConnection.DisconnectedInternal ( )
inlineprivate

◆ Equals()

override bool 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 BoltConnection.ExistsOnRemote ( BoltEntity  entity)
inline

◆ ExistsOnRemote() [2/2]

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

◆ GetHashCode()

override int BoltConnection.GetHashCode ( )
inline

A hash code for this connection

◆ GetSkippedUpdates()

int BoltConnection.GetSkippedUpdates ( BoltEntity  en)
inline

◆ operator bool() [1/2]

static implicit BoltObject.operator bool ( BoltObject  obj)
inlinestaticinherited

◆ operator bool() [2/2]

static implicit BoltConnection.operator bool ( BoltConnection  cn)
inlinestatic

◆ PacketDelivered()

internal void BoltConnection.PacketDelivered ( Packet  packet)
inlineprivate

◆ PacketLost()

internal void BoltConnection.PacketLost ( Packet  packet)
inlineprivate

◆ PacketReceived()

internal void BoltConnection.PacketReceived ( UdpPacket  udpPacket)
inlineprivate

◆ ReceiveData()

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

Receives the data.

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

◆ Send()

internal void BoltConnection.Send ( )
inlineprivate

◆ SendData()

void BoltConnection.SendData ( byte []  data)
inline

Sends the data.

Parameters
dataData.

◆ SetCanReceiveEntities()

void BoltConnection.SetCanReceiveEntities ( bool  v)
inline

◆ SetStreamBandwidth()

void 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);
}

◆ StepRemoteEntities()

internal bool BoltConnection.StepRemoteEntities ( )
inlineprivate

◆ StreamBytes()

void 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);
}

◆ SwitchPerfCounters()

internal void BoltConnection.SwitchPerfCounters ( )
inlineprivate

◆ ToString()

override string 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

◆ _binaryDataChannel

internal BinaryDataChannel BoltConnection._binaryDataChannel
private

◆ _bitsSecondIn

int BoltConnection._bitsSecondIn
private

◆ _bitsSecondInAcc

int BoltConnection._bitsSecondInAcc
private

◆ _bitsSecondOut

int BoltConnection._bitsSecondOut
private

◆ _bitsSecondOutAcc

int BoltConnection._bitsSecondOutAcc
private

◆ _canReceiveEntities

internal bool BoltConnection._canReceiveEntities = true
private

◆ _channels

BoltChannel [] BoltConnection._channels
private

◆ _commandChannel

internal EntityChannel.CommandChannel BoltConnection._commandChannel
private

◆ _commandStats

internal PacketTypeStats BoltConnection._commandStats
private

◆ _controlling

internal List<Entity> BoltConnection._controlling
private

◆ _controllingList

internal EntityList BoltConnection._controllingList
private

◆ _entityChannel

internal EntityChannel BoltConnection._entityChannel
private

◆ _eventChannel

internal EventChannel BoltConnection._eventChannel
private

◆ _eventsStats

internal PacketTypeStats BoltConnection._eventsStats
private

◆ _framesToStep

int BoltConnection._framesToStep
private

◆ _packetCounter

int BoltConnection._packetCounter
private

◆ _packetsReceived

int BoltConnection._packetsReceived
private

◆ _packetStatsIn

internal BoltRingBuffer<PacketStats> BoltConnection._packetStatsIn
private

◆ _packetStatsOut

internal BoltRingBuffer<PacketStats> BoltConnection._packetStatsOut
private

◆ _remoteFrameActual

int BoltConnection._remoteFrameActual
private

◆ _remoteFrameAdjust

bool BoltConnection._remoteFrameAdjust
private

◆ _remoteFrameDiff

int BoltConnection._remoteFrameDiff
private

◆ _remoteFrameEstimated

int BoltConnection._remoteFrameEstimated
private

◆ _remoteSceneLoading

internal SceneLoadState BoltConnection._remoteSceneLoading
private

◆ _sceneLoadChannel

internal SceneLoadChannel BoltConnection._sceneLoadChannel
private

◆ _stateStats

internal PacketTypeStats BoltConnection._stateStats
private

◆ _udpConnection

UdpConnection BoltConnection._udpConnection
private

Property Documentation

◆ AcceptToken

IProtocolToken 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 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 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 BoltConnection.CommandsStats
get

◆ ConnectionId

uint 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;
}
}

◆ ConnectToken

IProtocolToken BoltConnection.ConnectToken
getset

◆ DejitterFrames

int 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 BoltConnection.DisconnectReason
get

◆ DisconnectToken

IProtocolToken BoltConnection.DisconnectToken
getset

◆ EventsStats

PacketTypeStats BoltConnection.EventsStats
get

◆ HasControlOf

EntityList BoltConnection.HasControlOf
get

◆ IsLoadingMap

bool 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);
}
}

◆ list

object IBoltListNode<BoltConnection>. BoltConnection.list
getsetprivate

◆ next

BoltConnection IBoltListNode<BoltConnection>. BoltConnection.next
getsetprivate

◆ PingAliased

float 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 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;
}
}

◆ prev

BoltConnection IBoltListNode<BoltConnection>. BoltConnection.prev
getsetprivate

◆ RemoteEndPoint

UdpEndPoint 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 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;
}

◆ remoteFrameDiff

internal int BoltConnection.remoteFrameDiff
getprivate

◆ remoteFrameLatest

internal int BoltConnection.remoteFrameLatest
getprivate

◆ ScopedTo

EntityLookup BoltConnection.ScopedTo
get

◆ SendRateMultiplier

internal int BoltConnection.SendRateMultiplier
getprivate

◆ SourceOf

EntityLookup BoltConnection.SourceOf
get

◆ StatesStats

PacketTypeStats BoltConnection.StatesStats
get

◆ udpConnection

internal UdpConnection BoltConnection.udpConnection
getprivate

◆ UserData

object 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) {
}