Skip to main content

Class NetworkClient

This is a network client class used by the networking system. It contains a NetworkConnection that is used to connect to a network server. The handle connection state, messages handlers, and connection configuration. There can be many instances in a process at a time, but only one that is connected to a game server () that uses spawned objects. has an internal update function where it handles events from the transport layer. This includes asynchronous connect events, disconnect events and incoming data from a server.

Inheritance
System.Object
Syntax
public class NetworkClient : MonoBehaviour, IMessageSender

Fields

EnablePeerMetrics

Declaration
public bool EnablePeerMetrics

MetricsSize

Declaration
public int MetricsSize

SocketFactory

Declaration
public SocketFactory SocketFactory

ObjectManager

Declaration
public ClientObjectManager ObjectManager

DisconnectOnException

Declaration
public bool DisconnectOnException

RethrowException

Declaration
public bool RethrowException

RunInBackground

Declaration
public bool RunInBackground

Authenticator

Declaration
public AuthenticatorSettings Authenticator

ManualUpdate

Set to true if you want to manually call and and stop mirage from automatically calling them

Declaration
public bool ManualUpdate

Properties

Metrics

Declaration
public Metrics Metrics { get; }

PeerConfig

Config for peer, if not set will use default settings

Declaration
public Config PeerConfig { get; set; }

PeerPoolMetrics

Declaration
public PoolMetrics? PeerPoolMetrics { get; }

Started

Event fires when the client starts, before it has connected to the Server.

Declaration
public IAddLateEventUnity Started { get; }

Connected

Event fires once the Client has connected its Server.

Declaration
public IAddLateEventUnity<INetworkPlayer> Connected { get; }

Authenticated

Event fires after the Client connection has successfully been authenticated with its Server.

Declaration
public IAddLateEventUnity<INetworkPlayer> Authenticated { get; }

Disconnected

Event fires after the Client has disconnected from its Server and Cleanup has been called.

Declaration
public IAddLateEventUnity<ClientStoppedReason> Disconnected { get; }

Player

The NetworkConnection object this client is using.

Declaration
public INetworkPlayer Player { get; }

Active

active is true while a client is connecting/connected (= while the network is active)

Declaration
public bool Active { get; }

IsConnected

This gives the current connection status of the client.

Declaration
public bool IsConnected { get; }

World

Declaration
public NetworkWorld World { get; }

SyncVarSender

Declaration
public SyncVarSender SyncVarSender { get; }

MessageHandler

Declaration
public MessageHandler MessageHandler { get; }

IsLocalClient

Is this NetworkClient connected to a local server in host mode

Declaration
[Obsolete("use IsHost instead")]
public bool IsLocalClient { get; }

IsHost

Is this NetworkClient connected to a local server in host mode

Declaration
public bool IsHost { get; }

Methods

Connect(String, Nullable<UInt16>)

Connect client to a NetworkServer instance.

Declaration
public void Connect(string address = null, ushort? port = default(ushort? ))
Parameters
TypeNameDescription
System.Stringaddress
System.Nullable<System.UInt16>port

Disconnect()

Disconnect from server. The disconnect message will be invoked.

Declaration
public void Disconnect()

Send<T>(T, Channel)

This sends a network message with a message Id to the server. This message is sent on channel zero, which by default is the reliable channel. The message must be an instance of a class derived from MessageBase. The message id passed to Send() is used to identify the handler function to invoke on the server when the message is received.

Declaration
public void Send<T>(T message, Channel channelId = Channel.Reliable)
Parameters
TypeNameDescription
Tmessage
Mirage.ChannelchannelId

Send(ArraySegment<Byte>, Channel)

Declaration
public void Send(ArraySegment<byte> segment, Channel channelId = Channel.Reliable)
Parameters
TypeNameDescription
System.ArraySegment<System.Byte>segment
Mirage.ChannelchannelId

Send<T>(T, INotifyCallBack)

Declaration
public void Send<T>(T message, INotifyCallBack notifyCallBack)
Parameters
TypeNameDescription
Tmessage
Mirage.SocketLayer.INotifyCallBacknotifyCallBack

UpdateReceive()

Declaration
public void UpdateReceive()

UpdateSent()

Declaration
public void UpdateSent()