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.

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

Member Function Documentation

void BoltConnection.Disconnect ( )
inline

Disconnect this connection

Example: Terminating all connections.

1 void DisconnectAll() {
2  foreach(var connection in BoltNetwork.connections) {
3  connection.Disconnect();
4  }
5 }
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.

1 void DisconnectAll(int errorCode, string errorMessage) {
2  ServerMessage msg = new ServerMessage(errorCode, errorMessage);
3 
4  foreach(var connection in BoltNetwork.connections) {
5  connection.Disconnect(errorMessage);
6  }
7 }
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); }

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

A hash code for this connection

int BoltConnection.GetSkippedUpdates ( BoltEntity  en)
inline
static implicit BoltConnection.operator bool ( BoltConnection  cn)
inlinestatic
void BoltConnection.SetCanReceiveEntities ( bool  v)
inline
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.

1 public override void Connected(BoltConnection connection) {
2  connection.SetStreamBandwidth(1024 * 20);
3 }
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.

1 void SendCustomIcon(Texture2D myCustomIcon) {
2  byte[] data = myCustomIcon.EncodeToPNG();
3 
4  BoltNetwork.server.StreamBytes(Channels.PlayerIcon, data);
5 }
override string BoltConnection.ToString ( )
inline

The string representation of this connection

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

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

Property Documentation

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.

1 public override void Disconnected(BoltConnection connection, IProtocolToken token) {
2  ConnectionSettings connSettings = (ConnectionSettings)token;
3 
4  StartCoroutine(RemoveIfTimeout(connection, connSettings.maxTimeout));
5 }
int BoltConnection.BitsPerSecondIn
get

How many bits per second we are receiving in

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

1 void OnGUI() {
2  if(BoltNetwork.isConnected && BoltNetwork.isClient) {
3  GUILayout.Label("Ping:" + BoltNetwork.server.PingNetwork;
4  GUILayout.Label("Bandwidth Out:" + BoltNetwork.server.BitsPerSecondOut);
5  GUILayout.Label("Bandwidth In:" + BoltNetwork.server.BitsPerSecondIn);
6  }
7 }
int BoltConnection.BitsPerSecondOut
get

How many bits per second we are sending out

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

1 void OnGUI() {
2  if(BoltNetwork.isConnected && BoltNetwork.isClient) {
3  GUILayout.Label("Ping:" + BoltNetwork.server.pingNetwork;
4  GUILayout.Label("Bandwidth Out:" + BoltNetwork.server.bitsPerSecondIn);
5  GUILayout.Label("Bandwidth In:" + BoltNetwork.server.bitsPerSecondOut);
6  }
7 }
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

1 uint getID()
2 {
3  if (BoltNetwork.isClient)
4  {
5  //my Id
6  return BoltNetwork.server.ConnectionId;
7  }
8  else
9  {
10  //Id of first client
11  return BoltNetwork.clients.First().ConnectionId;
12  }
13 }
IProtocolToken BoltConnection.ConnectToken
getset
int BoltConnection.DejitterFrames
get

The dejitter delay in number of frames

Example: Showing the dejitter delay frames and ping.

1 void OnGUI() {
2  if(BoltNetwork.isConnected && BoltNetwork.isClient) {
3  GUILayout.Label("Ping:" + BoltNetwork.server.pingNetwork;
4  GUILayout.Label("Dejitter Delay:" + BoltNetwork.server.DejitterFrames;
5  }
6 }
IProtocolToken BoltConnection.DisconnectToken
getset
EntityList BoltConnection.HasControlOf
get
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.

1 public override void Disconnected(BoltConnection connection) {
2  if(connection.isLoadingMap) {
3  PlayerEntityList.instance.RemoveFor(connection);
4  }
5 }
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.

1 void OnGUI() {
2  if(BoltNetwork.isConnected && BoltNetwork.isClient) {
3  GUILayout.Label("Ping:" + BoltNetwork.server.PingNetwork;
4  GUILayout.Label("Ping (Aliased):" + BoltNetwork.server.PingAliased;
5  }
6 }
float BoltConnection.PingNetwork
get

The round-trip time on the network

Example: Displaying the network ping when in debug mode.

1 void OnGUI() {
2  if(BoltNetwork.isConnected && BoltNetwork.isClient) {
3  GUILayout.Label("Ping:" + BoltNetwork.server.PingNetwork;
4  }
5 }
UdpEndPoint BoltConnection.RemoteEndPoint
get

Remote end point of this connection

Example: Logging the address of new connections

1 public override void Connected(BoltConnection connection) {
2  ServerLog.Write(string.Format("[{0}:{1}] New Connection", connection.remoteEndPoint.Address, connection.remoteEndPoint.Port);
3 }
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.

1 float EstimateFrameDiff() {
2  int count
3  float avg;
4 
5  foreach(BoltConnection client in BoltNetwork.clients) {
6  count++;
7  avg += BoltNetwork.serverFrame - client.remoteFrame;
8  }
9  avg = avg / count;
10  return avg;
11 }
EntityLookup BoltConnection.ScopedTo
get
EntityLookup BoltConnection.SourceOf
get
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.

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