Skip to content

Mirror::Transport

Abstract transport layer component More...

Inherits from MonoBehaviour

Inherited by KcpTransport, FallbackTransport, LLAPITransport, MiddlewareTransport, MultiplexTransport, SimpleWebTransport, TelepathyTransport

Public Functions

Name
virtual abstract bool Available() =0
Is this transport available in the current platform?
virtual abstract bool ClientConnected() =0
Determines if we are currently connected to the server
virtual abstract void ClientConnect(string address) =0
Establish a connection to a server
virtual void ClientConnect(Uri uri)
Establish a connection to a server
virtual abstract void ClientSend(int channelId, ArraySegment< byte > segment) =0
Send data to the server
virtual abstract void ClientDisconnect() =0
Disconnect this client from the server
virtual abstract Uri ServerUri() =0
Retrieves the address of this server. Useful for network discovery
virtual abstract bool ServerActive() =0
Determines if the server is up and running
virtual abstract void ServerStart() =0
Start listening for clients
virtual abstract void ServerSend(int connectionId, int channelId, ArraySegment< byte > segment) =0
Send data to a client.
virtual abstract bool ServerDisconnect(int connectionId) =0
Disconnect a client from this server. Useful to kick people out.
virtual abstract string ServerGetClientAddress(int connectionId) =0
Get the client address
virtual abstract void ServerStop() =0
Stop listening for clients and disconnect all existing clients
virtual abstract int GetMaxPacketSize(int channelId =Channels.DefaultReliable) =0
The maximum packet size for a given channel. Unreliable transports usually can only deliver small packets. Reliable fragmented channels can usually deliver large ones.
virtual abstract void Shutdown() =0
Shut down the transport, both as client and server
void Update()
virtual void OnApplicationQuit()
called when quitting the application by closing the window / pressing stop in the editor

Public Attributes

Name
Transport activeTransport
The current transport used by Mirror.
UnityEvent OnClientConnected
Notify subscribers when when this client establish a successful connection to the server
ClientDataReceivedEvent OnClientDataReceived
Notify subscribers when this client receive data from the server
UnityEventException OnClientError
Notify subscribers when this client encounters an error communicating with the server
UnityEvent OnClientDisconnected
Notify subscribers when this client disconnects from the server
UnityEventInt OnServerConnected
Notify subscribers when a client connects to this server
ServerDataReceivedEvent OnServerDataReceived
Notify subscribers when this server receives data from the client
UnityEventIntException OnServerError
Notify subscribers when this server has some problem communicating with the client
UnityEventInt OnServerDisconnected
Notify subscribers when a client disconnects from this server

Detailed Description

class Mirror::Transport;

Abstract transport layer component

note: Not all transports need a port, so add it to yours if needed.

Public Functions Documentation

function Available

virtual abstract bool Available() =0

Is this transport available in the current platform?

Return: True if this transport works in the current platform

Reimplemented by: Mirror::MiddlewareTransport::Available, Mirror::MultiplexTransport::Available, Mirror::FallbackTransport::Available, Mirror::TelepathyTransport::Available, kcp2k::KcpTransport::Available, Mirror::SimpleWeb::SimpleWebTransport::Available, Mirror::LLAPITransport::Available

Some transports might only be available in mobile

Many will not work in webgl

Example usage: return Application.platform == RuntimePlatform.WebGLPlayer

function ClientConnected

virtual abstract bool ClientConnected() =0

Determines if we are currently connected to the server

Return: True if a connection has been established to the server

Reimplemented by: Mirror::MiddlewareTransport::ClientConnected, Mirror::TelepathyTransport::ClientConnected, kcp2k::KcpTransport::ClientConnected, Mirror::FallbackTransport::ClientConnected, Mirror::MultiplexTransport::ClientConnected, Mirror::LLAPITransport::ClientConnected, Mirror::SimpleWeb::SimpleWebTransport::ClientConnected

function ClientConnect

virtual abstract void ClientConnect(
    string address
) =0

Establish a connection to a server

Parameters:

  • address The IP address or FQDN of the server we are trying to connect to

Reimplemented by: Mirror::MiddlewareTransport::ClientConnect, Mirror::TelepathyTransport::ClientConnect, Mirror::MultiplexTransport::ClientConnect, kcp2k::KcpTransport::ClientConnect, Mirror::FallbackTransport::ClientConnect, Mirror::SimpleWeb::SimpleWebTransport::ClientConnect, Mirror::LLAPITransport::ClientConnect

function ClientConnect

inline virtual void ClientConnect(
    Uri uri
)

Establish a connection to a server

Parameters:

  • uri The address of the server we are trying to connect to

Reimplemented by: Mirror::TelepathyTransport::ClientConnect, Mirror::FallbackTransport::ClientConnect, Mirror::MultiplexTransport::ClientConnect, Mirror::LLAPITransport::ClientConnect

function ClientSend

virtual abstract void ClientSend(
    int channelId,
    ArraySegment< byte > segment
) =0

Send data to the server

Parameters:

  • channelId The channel to use. 0 is the default channel, but some transports might want to provide unreliable, encrypted, compressed, or any other feature as new channels
  • segment The data to send to the server. Will be recycled after returning, so either use it directly or copy it internally. This allows for allocation-free sends!

Reimplemented by: Mirror::MiddlewareTransport::ClientSend, kcp2k::KcpTransport::ClientSend, Mirror::TelepathyTransport::ClientSend, Mirror::FallbackTransport::ClientSend, Mirror::MultiplexTransport::ClientSend, Mirror::LLAPITransport::ClientSend, Mirror::SimpleWeb::SimpleWebTransport::ClientSend

function ClientDisconnect

virtual abstract void ClientDisconnect() =0

Disconnect this client from the server

Reimplemented by: Mirror::MiddlewareTransport::ClientDisconnect, kcp2k::KcpTransport::ClientDisconnect, Mirror::FallbackTransport::ClientDisconnect, Mirror::MultiplexTransport::ClientDisconnect, Mirror::TelepathyTransport::ClientDisconnect, Mirror::SimpleWeb::SimpleWebTransport::ClientDisconnect, Mirror::LLAPITransport::ClientDisconnect

function ServerUri

virtual abstract Uri ServerUri() =0

Retrieves the address of this server. Useful for network discovery

Return: the url at which this server can be reached

Reimplemented by: Mirror::MiddlewareTransport::ServerUri, kcp2k::KcpTransport::ServerUri, Mirror::FallbackTransport::ServerUri, Mirror::TelepathyTransport::ServerUri, Mirror::MultiplexTransport::ServerUri, Mirror::LLAPITransport::ServerUri, Mirror::SimpleWeb::SimpleWebTransport::ServerUri

function ServerActive

virtual abstract bool ServerActive() =0

Determines if the server is up and running

Return: true if the transport is ready for connections from clients

Reimplemented by: Mirror::MiddlewareTransport::ServerActive, kcp2k::KcpTransport::ServerActive, Mirror::FallbackTransport::ServerActive, Mirror::TelepathyTransport::ServerActive, Mirror::MultiplexTransport::ServerActive, Mirror::SimpleWeb::SimpleWebTransport::ServerActive, Mirror::LLAPITransport::ServerActive

function ServerStart

virtual abstract void ServerStart() =0

Start listening for clients

Reimplemented by: Mirror::MiddlewareTransport::ServerStart, kcp2k::KcpTransport::ServerStart, Mirror::FallbackTransport::ServerStart, Mirror::TelepathyTransport::ServerStart, Mirror::SimpleWeb::SimpleWebTransport::ServerStart, Mirror::MultiplexTransport::ServerStart, Mirror::LLAPITransport::ServerStart

function ServerSend

virtual abstract void ServerSend(
    int connectionId,
    int channelId,
    ArraySegment< byte > segment
) =0

Send data to a client.

Parameters:

  • connectionId The client connection id to send the data to
  • channelId The channel to be used. Transports can use channels to implement other features such as unreliable, encryption, compression, etc...
  • data

Reimplemented by: Mirror::MiddlewareTransport::ServerSend, kcp2k::KcpTransport::ServerSend, Mirror::FallbackTransport::ServerSend, Mirror::TelepathyTransport::ServerSend, Mirror::MultiplexTransport::ServerSend, Mirror::SimpleWeb::SimpleWebTransport::ServerSend, Mirror::LLAPITransport::ServerSend

function ServerDisconnect

virtual abstract bool ServerDisconnect(
    int connectionId
) =0

Disconnect a client from this server. Useful to kick people out.

Parameters:

  • connectionId the id of the client to disconnect

Return: true if the client was kicked

Reimplemented by: Mirror::MiddlewareTransport::ServerDisconnect, kcp2k::KcpTransport::ServerDisconnect, Mirror::FallbackTransport::ServerDisconnect, Mirror::MultiplexTransport::ServerDisconnect, Mirror::TelepathyTransport::ServerDisconnect, Mirror::SimpleWeb::SimpleWebTransport::ServerDisconnect, Mirror::LLAPITransport::ServerDisconnect

function ServerGetClientAddress

virtual abstract string ServerGetClientAddress(
    int connectionId
) =0

Get the client address

Parameters:

  • connectionId id of the client

Return: address of the client

Reimplemented by: Mirror::MiddlewareTransport::ServerGetClientAddress, kcp2k::KcpTransport::ServerGetClientAddress, Mirror::FallbackTransport::ServerGetClientAddress, Mirror::MultiplexTransport::ServerGetClientAddress, Mirror::TelepathyTransport::ServerGetClientAddress, Mirror::SimpleWeb::SimpleWebTransport::ServerGetClientAddress, Mirror::LLAPITransport::ServerGetClientAddress

function ServerStop

virtual abstract void ServerStop() =0

Stop listening for clients and disconnect all existing clients

Reimplemented by: Mirror::MiddlewareTransport::ServerStop, kcp2k::KcpTransport::ServerStop, Mirror::FallbackTransport::ServerStop, Mirror::SimpleWeb::SimpleWebTransport::ServerStop, Mirror::TelepathyTransport::ServerStop, Mirror::MultiplexTransport::ServerStop, Mirror::LLAPITransport::ServerStop

function GetMaxPacketSize

virtual abstract int GetMaxPacketSize(
    int channelId =Channels.DefaultReliable
) =0

The maximum packet size for a given channel. Unreliable transports usually can only deliver small packets. Reliable fragmented channels can usually deliver large ones.

Parameters:

  • channelId channel id

Return: the size in bytes that can be sent via the provided channel

Reimplemented by: Mirror::MiddlewareTransport::GetMaxPacketSize, Mirror::SimpleWeb::SimpleWebTransport::GetMaxPacketSize, kcp2k::KcpTransport::GetMaxPacketSize, Mirror::FallbackTransport::GetMaxPacketSize, Mirror::TelepathyTransport::GetMaxPacketSize, Mirror::MultiplexTransport::GetMaxPacketSize, Mirror::LLAPITransport::GetMaxPacketSize

GetMaxPacketSize needs to return a value at all times. Even if the Transport isn't running, or isn't Available(). This is because Fallback and Multiplex transports need to find the smallest possible packet size at runtime.

function Shutdown

virtual abstract void Shutdown() =0

Shut down the transport, both as client and server

Reimplemented by: Mirror::MiddlewareTransport::Shutdown, Mirror::SimpleWeb::SimpleWebTransport::Shutdown, kcp2k::KcpTransport::Shutdown, Mirror::FallbackTransport::Shutdown, Mirror::TelepathyTransport::Shutdown, Mirror::MultiplexTransport::Shutdown, Mirror::LLAPITransport::Shutdown

function Update

inline void Update()

function OnApplicationQuit

inline virtual void OnApplicationQuit()

called when quitting the application by closing the window / pressing stop in the editor

virtual so that inheriting classes' OnApplicationQuit() can call base.OnApplicationQuit() too

Public Attributes Documentation

variable activeTransport

static Transport activeTransport;

The current transport used by Mirror.

variable OnClientConnected

UnityEvent OnClientConnected = new UnityEvent();

Notify subscribers when when this client establish a successful connection to the server

variable OnClientDataReceived

ClientDataReceivedEvent OnClientDataReceived = new [ClientDataReceivedEvent](/Documentation/Cops%20And%20Robbers/Classes/classMirror_1_1ClientDataReceivedEvent/)();

Notify subscribers when this client receive data from the server

variable OnClientError

UnityEventException OnClientError = new [UnityEventException](/Documentation/Cops%20And%20Robbers/Classes/classMirror_1_1UnityEventException/)();

Notify subscribers when this client encounters an error communicating with the server

variable OnClientDisconnected

UnityEvent OnClientDisconnected = new UnityEvent();

Notify subscribers when this client disconnects from the server

variable OnServerConnected

UnityEventInt OnServerConnected = new [UnityEventInt](/Documentation/Cops%20And%20Robbers/Classes/classMirror_1_1UnityEventInt/)();

Notify subscribers when a client connects to this server

variable OnServerDataReceived

ServerDataReceivedEvent OnServerDataReceived = new [ServerDataReceivedEvent](/Documentation/Cops%20And%20Robbers/Classes/classMirror_1_1ServerDataReceivedEvent/)();

Notify subscribers when this server receives data from the client

variable OnServerError

UnityEventIntException OnServerError = new [UnityEventIntException](/Documentation/Cops%20And%20Robbers/Classes/classMirror_1_1UnityEventIntException/)();

Notify subscribers when this server has some problem communicating with the client

variable OnServerDisconnected

UnityEventInt OnServerDisconnected = new [UnityEventInt](/Documentation/Cops%20And%20Robbers/Classes/classMirror_1_1UnityEventInt/)();

Notify subscribers when a client disconnects from this server


Updated on 25 January 2021 at 09:57:17 UTC