Photon Bolt Engine API
Networking Middleware
Public Member Functions | Static Public Member Functions | Properties | List of all members
BoltConnection Class Reference

The connection to a remote endpoint More...

Inheritance diagram for BoltConnection:
BoltObject

Public Member Functions

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

Static Public Member Functions

static implicit operator bool (BoltConnection cn)
 
- Static Public Member Functions inherited from BoltObject
static implicit operator bool (BoltObject obj)
 

Properties

bool IsLoadingMap [get]
 Returns true if the remote computer on the other end of this connection is loading a map currently, otherwise false More...
 
EntityLookup ScopedTo [get]
 
EntityLookup SourceOf [get]
 
EntityList HasControlOf [get]
 
int RemoteFrame [get]
 The estimated frame of the simulation running at the other end of this connection More...
 
IProtocolToken ConnectToken [get, set]
 
IProtocolToken DisconnectToken [get, set]
 
IProtocolToken AcceptToken [get, set]
 A data token that was passed by the server when accepting the connection More...
 
float PingNetwork [get]
 The round-trip time on the network More...
 
int DejitterFrames [get]
 The dejitter delay in number of frames More...
 
float PingAliased [get]
 The round-trip time across the network, including processing delays and acks 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...
 
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...
 
UdpEndPoint RemoteEndPoint [get]
 Remote end point of this connection More...
 
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 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)
inline

Disconnect this connection with custom data

Parameters
tokenA data token

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

static implicit BoltConnection.operator bool ( BoltConnection  cn)
inlinestatic

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

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

◆ 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());
}

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

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

◆ DisconnectToken

IProtocolToken BoltConnection.DisconnectToken
getset

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

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

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

◆ ScopedTo

EntityLookup BoltConnection.ScopedTo
get

◆ SourceOf

EntityLookup BoltConnection.SourceOf
get

◆ 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) {
BoltNetwork.Destroy((BoltEntity)connection.UserData);
}