Skip to content

kcp2k::KcpTransport

Inherits from Transport, MonoBehaviour

Public Functions

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

Public Attributes

Name
const string Scheme
ushort Port
bool NoDelay
uint Interval
int FastResend
bool CongestionWindow
uint SendWindowSize
uint ReceiveWindowSize
bool debugGUI

Additional inherited members

Public Functions inherited from Transport

Name
void Update()
virtual void OnApplicationQuit()
called when quitting the application by closing the window / pressing stop in the editor

Public Attributes inherited from Transport

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

Public Functions Documentation

function Available

virtual override bool Available()

Is this transport available in the current platform?

Return: True if this transport works in the current platform

Reimplements: Mirror::Transport::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 override bool ClientConnected()

Determines if we are currently connected to the server

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

Reimplements: Mirror::Transport::ClientConnected

function ClientConnect

inline virtual override void ClientConnect(
    string address
)

Establish a connection to a server

Parameters:

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

Reimplements: Mirror::Transport::ClientConnect

function ClientSend

inline virtual override void ClientSend(
    int channelId,
    ArraySegment< byte > segment
)

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!

Reimplements: Mirror::Transport::ClientSend

function ClientDisconnect

virtual override void ClientDisconnect()

Disconnect this client from the server

Reimplements: Mirror::Transport::ClientDisconnect

function LateUpdate

inline void LateUpdate()

function ServerUri

inline virtual override Uri ServerUri()

Retrieves the address of this server. Useful for network discovery

Return: the url at which this server can be reached

Reimplements: Mirror::Transport::ServerUri

function ServerActive

virtual override bool ServerActive()

Determines if the server is up and running

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

Reimplements: Mirror::Transport::ServerActive

function ServerStart

virtual override void ServerStart()

Start listening for clients

Reimplements: Mirror::Transport::ServerStart

function ServerSend

inline virtual override void ServerSend(
    int connectionId,
    int channelId,
    ArraySegment< byte > segment
)

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

Reimplements: Mirror::Transport::ServerSend

function ServerDisconnect

inline virtual override bool ServerDisconnect(
    int connectionId
)

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

Reimplements: Mirror::Transport::ServerDisconnect

function ServerGetClientAddress

virtual override string ServerGetClientAddress(
    int connectionId
)

Get the client address

Parameters:

  • connectionId id of the client

Return: address of the client

Reimplements: Mirror::Transport::ServerGetClientAddress

function ServerStop

virtual override void ServerStop()

Stop listening for clients and disconnect all existing clients

Reimplements: Mirror::Transport::ServerStop

function Shutdown

inline virtual override void Shutdown()

Shut down the transport, both as client and server

Reimplements: Mirror::Transport::Shutdown

function GetMaxPacketSize

virtual override int GetMaxPacketSize(
    int channelId =Channels.DefaultReliable
)

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

Reimplements: Mirror::Transport::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 ToString

inline override string ToString()

Public Attributes Documentation

variable Scheme

const string Scheme = "kcp";

variable Port

ushort Port = 7777;

variable NoDelay

bool NoDelay = true;

variable Interval

uint Interval = 10;

variable FastResend

int FastResend = 0;

variable CongestionWindow

bool CongestionWindow = true;

variable SendWindowSize

uint SendWindowSize = 128;

variable ReceiveWindowSize

uint ReceiveWindowSize = Kcp.WND_RCV;

variable debugGUI

bool debugGUI;

Updated on 17 January 2021 at 14:41:11 UTC