Class NetworkConnection
A container for a connected client used to perform actions on and gather information for the declared client.
Inheritance
Implements
Inherited Members
Namespace: FishNet.Connection
Assembly: FishNet.Runtime.dll
Syntax
public class NetworkConnection : IEquatable<NetworkConnection>
Fields
ClientId
Unique Id for this connection.
Declaration
public int ClientId
Field Value
Type | Description |
---|---|
System.Int32 |
CLIENTID_UNCOMPRESSED_RESERVE_BYTES
Number of bytes to reserve for a connectionId if writing the value uncompressed.
Declaration
public const int CLIENTID_UNCOMPRESSED_RESERVE_BYTES = 4
Field Value
Type | Description |
---|---|
System.Int32 |
CustomData
Custom data associated with this connection which may be modified by the user. The value of this field are not synchronized over the network.
Declaration
public object CustomData
Field Value
Type | Description |
---|---|
System.Object |
LevelOfDetails
Level of detail for each NetworkObject. Since this is called frequently this field is intentionally not an accessor to increase performance.
Declaration
public Dictionary<NetworkObject, NetworkConnection.LevelOfDetailData> LevelOfDetails
Field Value
Type | Description |
---|---|
System.Collections.Generic.Dictionary<NetworkObject, NetworkConnection.LevelOfDetailData> |
MAXIMUM_CLIENTID_VALUE
Maximum value a ClientId can be.
Declaration
public const int MAXIMUM_CLIENTID_VALUE = 2147483646
Field Value
Type | Description |
---|---|
System.Int32 |
Objects
Objects owned by this connection. Available to this connection and server.
Declaration
public HashSet<NetworkObject> Objects
Field Value
Type | Description |
---|---|
System.Collections.Generic.HashSet<NetworkObject> |
SIMULATED_CLIENTID_VALUE
Value to use as a ClientId when simulating a local client without actually using a socket.
Declaration
public const int SIMULATED_CLIENTID_VALUE = 2147483647
Field Value
Type | Description |
---|---|
System.Int32 |
UNSET_CLIENTID_VALUE
Value used when ClientId has not been set.
Declaration
public const int UNSET_CLIENTID_VALUE = -1
Field Value
Type | Description |
---|---|
System.Int32 |
Properties
Authenticated
Declaration
[Obsolete("Use IsAuthenticated.")]
public bool Authenticated { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Disconnecting
True if this connection is being disconnected. Only available to server.
Declaration
public bool Disconnecting { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
FirstObject
The first object within Objects.
Declaration
public NetworkObject FirstObject { get; }
Property Value
Type | Description |
---|---|
NetworkObject |
IsActive
True if this connection IsValid and not Disconnecting.
Declaration
public bool IsActive { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsAuthenticated
True if this connection is authenticated. Only available to server.
Declaration
public bool IsAuthenticated { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsHost
Returns true if this connection is a clientHost.
Declaration
public bool IsHost { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsLocalClient
Returns if this connection is for the local client.
Declaration
public bool IsLocalClient { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsValid
True if this connection is valid. An invalid connection indicates no client is set for this reference.
Declaration
public bool IsValid { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
LocalTick
Approximate local tick as it is on this connection. This also contains the last set value for local and remote.
Declaration
public EstimatedTick LocalTick { get; }
Property Value
Type | Description |
---|---|
EstimatedTick |
NetworkManager
NetworkManager managing this class.
Declaration
public NetworkManager NetworkManager { get; }
Property Value
Type | Description |
---|---|
NetworkManager |
PacketTick
Tick of the last packet received from this connection which was not out of order. This value is only available on the server.
Declaration
public EstimatedTick PacketTick { get; }
Property Value
Type | Description |
---|---|
EstimatedTick |
ReplicateTick
Approximate replicate tick on the server for this connection. This also contains the last set value for local and remote.
Declaration
public EstimatedTick ReplicateTick { get; }
Property Value
Type | Description |
---|---|
EstimatedTick |
Scenes
Scenes this connection is in. Available to this connection and server.
Declaration
public HashSet<Scene> Scenes { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.HashSet<UnityEngine.SceneManagement.Scene> |
TransportIndex
TransportIndex this connection is on. For security reasons this value will be unset on clients if this is not their connection.
Declaration
public int TransportIndex { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
Broadcast<T>(T, Boolean, Channel)
Sends a broadcast to this connection.
Declaration
public void Broadcast<T>(T message, bool requireAuthenticated = true, Channel channel = Channel.Reliable)
where T : struct, IBroadcast
Parameters
Type | Name | Description |
---|---|---|
T | message | Broadcast data being sent; for example: an instance of your broadcast type. |
System.Boolean | requireAuthenticated | True if the client must be authenticated for this broadcast to send. |
Channel | channel | Channel to send on. |
Type Parameters
Name | Description |
---|---|
T | Type of broadcast to send. |
Disconnect(Boolean)
Disconnects this connection.
Declaration
public void Disconnect(bool immediately)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | immediately | True to disconnect immediately. False to send any pending data first. |
Equals(NetworkConnection)
Declaration
public bool Equals(NetworkConnection nc)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnection | nc |
Returns
Type | Description |
---|---|
System.Boolean |
Equals(Object)
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
GetAddress()
Returns the address of this connection.
Declaration
public string GetAddress()
Returns
Type | Description |
---|---|
System.String |
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
Kick(KickReason, LoggingType, String)
Kicks a connection immediately while invoking OnClientKick.
Declaration
public void Kick(KickReason kickReason, LoggingType loggingType = LoggingType.Common, string log = "")
Parameters
Type | Name | Description |
---|---|---|
KickReason | kickReason | Reason client is being kicked. |
LoggingType | loggingType | How to print logging as. |
System.String | log | Optional message to be debug logged. |
Kick(Reader, KickReason, LoggingType, String)
Kicks a connection immediately while invoking OnClientKick.
Declaration
public void Kick(Reader reader, KickReason kickReason, LoggingType loggingType = LoggingType.Common, string log = "")
Parameters
Type | Name | Description |
---|---|---|
Reader | reader | Reader to clear before kicking. |
KickReason | kickReason | Reason client is being kicked. |
LoggingType | loggingType | How to print logging as. |
System.String | log | Optional message to be debug logged. |
LoadedStartScenes()
True if connection has loaded start scenes. Available to this connection and server.
Declaration
public bool LoadedStartScenes()
Returns
Type | Description |
---|---|
System.Boolean |
LoadedStartScenes(Boolean)
Declaration
public bool LoadedStartScenes(bool asServer)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | asServer |
Returns
Type | Description |
---|---|
System.Boolean |
SetFirstObject(NetworkObject)
Sets a custom FirstObject. This connection must be owner of the specified object.
Declaration
public void SetFirstObject(NetworkObject nob)
Parameters
Type | Name | Description |
---|---|---|
NetworkObject | nob |
ToString()
Outputs data about this connection as a string.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |
Overrides
Events
OnLoadedStartScenes
Called after this connection has loaded start scenes. Boolean will be true if asServer. Available to this connection and server.
Declaration
public event Action<NetworkConnection, bool> OnLoadedStartScenes
Event Type
Type | Description |
---|---|
System.Action<NetworkConnection, System.Boolean> |
OnObjectAdded
Called after connection gains ownership of an object, and after the object has been added to Objects. Available to this connection and server.
Declaration
public event Action<NetworkObject> OnObjectAdded
Event Type
Type | Description |
---|---|
System.Action<NetworkObject> |
OnObjectRemoved
Called after connection loses ownership of an object, and after the object has been removed from Objects. Available to this connection and server.
Declaration
public event Action<NetworkObject> OnObjectRemoved
Event Type
Type | Description |
---|---|
System.Action<NetworkObject> |
Operators
Equality(NetworkConnection, NetworkConnection)
Declaration
public static bool operator ==(NetworkConnection a, NetworkConnection b)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnection | a | |
NetworkConnection | b |
Returns
Type | Description |
---|---|
System.Boolean |
Inequality(NetworkConnection, NetworkConnection)
Declaration
public static bool operator !=(NetworkConnection a, NetworkConnection b)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnection | a | |
NetworkConnection | b |
Returns
Type | Description |
---|---|
System.Boolean |