Class Transport
Processes connection states, and data sent to and from a socket.
Inheritance
Inherited Members
Namespace: FishNet.Transporting
Assembly: FishNet.Runtime.dll
Syntax
public abstract class Transport : MonoBehaviour
Properties
Index
Index this transport belongs to when using multiple transports at once.
Declaration
public int Index { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
NetworkManager
NetworkManager for this transport.
Declaration
public NetworkManager NetworkManager { get; }
Property Value
Type | Description |
---|---|
NetworkManager |
Methods
GetClientAddress()
Returns which address the client will connect to.
Declaration
public virtual string GetClientAddress()
Returns
Type | Description |
---|---|
System.String |
GetConnectionAddress(Int32)
Gets the address of a remote connection Id.
Declaration
public abstract string GetConnectionAddress(int connectionId)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | connectionId | Connectionid to get the address for. |
Returns
Type | Description |
---|---|
System.String |
GetConnectionState(Boolean)
Gets the current local ConnectionState.
Declaration
public abstract LocalConnectionState GetConnectionState(bool server)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | server | True if getting ConnectionState for the server. |
Returns
Type | Description |
---|---|
LocalConnectionState |
GetConnectionState(Int32)
Gets the current ConnectionState of a client connected to the server. Can only be called on the server.
Declaration
public abstract RemoteConnectionState GetConnectionState(int connectionId)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | connectionId | ConnectionId to get ConnectionState for. |
Returns
Type | Description |
---|---|
RemoteConnectionState |
GetMaximumClients()
Returns the maximum number of clients allowed to connect to the server. If the transport does not support this method the value -1 is returned.
Declaration
public virtual int GetMaximumClients()
Returns
Type | Description |
---|---|
System.Int32 | Maximum clients transport allows. |
GetMTU(Byte)
Gets the MTU for a channel.
Declaration
public abstract int GetMTU(byte channel)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | channel | Channel to get MTU for. |
Returns
Type | Description |
---|---|
System.Int32 | MTU of channel. |
GetPort()
Gets which port to use.
Declaration
public virtual ushort GetPort()
Returns
Type | Description |
---|---|
System.UInt16 |
GetServerBindAddress(IPAddressType)
Gets which address the server will bind to.
Declaration
public virtual string GetServerBindAddress(IPAddressType addressType)
Parameters
Type | Name | Description |
---|---|---|
IPAddressType | addressType | Address type to return. |
Returns
Type | Description |
---|---|
System.String |
GetTimeout(Boolean)
Gets how long in seconds until either the server or client socket must go without data before being timed out.
Declaration
public virtual float GetTimeout(bool asServer)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | asServer | True to get the timeout for the server socket, false for the client socket. |
Returns
Type | Description |
---|---|
System.Single |
HandleClientConnectionState(ClientConnectionStateArgs)
Handles a ConnectionStateArgs for the local client.
Declaration
public abstract void HandleClientConnectionState(ClientConnectionStateArgs connectionStateArgs)
Parameters
Type | Name | Description |
---|---|---|
ClientConnectionStateArgs | connectionStateArgs | Data being handled. |
HandleClientReceivedDataArgs(ClientReceivedDataArgs)
Handles a ClientReceivedDataArgs.
Declaration
public abstract void HandleClientReceivedDataArgs(ClientReceivedDataArgs receivedDataArgs)
Parameters
Type | Name | Description |
---|---|---|
ClientReceivedDataArgs | receivedDataArgs | Data being handled. |
HandleRemoteConnectionState(RemoteConnectionStateArgs)
Handles a ConnectionStateArgs for a remote client.
Declaration
public abstract void HandleRemoteConnectionState(RemoteConnectionStateArgs connectionStateArgs)
Parameters
Type | Name | Description |
---|---|---|
RemoteConnectionStateArgs | connectionStateArgs | Data being handled. |
HandleServerConnectionState(ServerConnectionStateArgs)
Handles a ConnectionStateArgs for the local server.
Declaration
public abstract void HandleServerConnectionState(ServerConnectionStateArgs connectionStateArgs)
Parameters
Type | Name | Description |
---|---|---|
ServerConnectionStateArgs | connectionStateArgs | Data being handled. |
HandleServerReceivedDataArgs(ServerReceivedDataArgs)
Handles a ServerReceivedDataArgs.
Declaration
public abstract void HandleServerReceivedDataArgs(ServerReceivedDataArgs receivedDataArgs)
Parameters
Type | Name | Description |
---|---|---|
ServerReceivedDataArgs | receivedDataArgs | Data being handled. |
Initialize(NetworkManager, Int32)
Initializes the transport. Use this instead of Awake.
Index this transport belongs to when using multiple transports at once.Declaration
public virtual void Initialize(NetworkManager networkManager, int transportIndex)
Parameters
Type | Name | Description |
---|---|---|
NetworkManager | networkManager | |
System.Int32 | transportIndex |
IsLocalTransport(Int32)
Returns if the transport is only run locally, offline. While true several security checks are disabled.
Declaration
public virtual bool IsLocalTransport(int connectionid)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | connectionid | Optional connectionId to check against. |
Returns
Type | Description |
---|---|
System.Boolean |
IterateIncoming(Boolean)
Processes data received by the socket.
Declaration
public abstract void IterateIncoming(bool server)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | server | True to process data received on the server. |
IterateOutgoing(Boolean)
Processes data to be sent by the socket.
Declaration
public abstract void IterateOutgoing(bool server)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | server | True to process data received on the server. |
SendToClient(Byte, ArraySegment<Byte>, Int32)
Sends to a client.
Declaration
public abstract void SendToClient(byte channelId, ArraySegment<byte> segment, int connectionId)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | channelId | Channel to use. |
System.ArraySegment<System.Byte> | segment | Data to send. |
System.Int32 | connectionId | ConnectionId to send to. When sending to clients can be used to specify which connection to send to. |
SendToServer(Byte, ArraySegment<Byte>)
Sends to the server.
Declaration
public abstract void SendToServer(byte channelId, ArraySegment<byte> segment)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | channelId | Channel to use. |
System.ArraySegment<System.Byte> | segment | Data to send. |
SetClientAddress(String)
Sets which address the client will connect to.
Declaration
public virtual void SetClientAddress(string address)
Parameters
Type | Name | Description |
---|---|---|
System.String | address | Address client will connect to. |
SetMaximumClients(Int32)
Sets the maximum number of clients allowed to connect to the server. If applied at runtime and clients exceed this value existing clients will stay connected but new clients may not connect.
Declaration
public virtual void SetMaximumClients(int value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | Maximum clients to allow. |
SetPort(UInt16)
Sets which port to use.
Declaration
public virtual void SetPort(ushort port)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | port | Port to use. |
SetServerBindAddress(String, IPAddressType)
Sets which address the server will bind to.
Declaration
public virtual void SetServerBindAddress(string address, IPAddressType addressType)
Parameters
Type | Name | Description |
---|---|---|
System.String | address | Address server will bind to. |
IPAddressType | addressType | Address type to set. |
SetTimeout(Single, Boolean)
Sets how long in seconds until either the server or client socket must go without data before being timed out.
Declaration
public virtual void SetTimeout(float value, bool asServer)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | |
System.Boolean | asServer | True to set the timeout for the server socket, false for the client socket. |
Shutdown()
Stops both client and server.
Declaration
public abstract void Shutdown()
StartConnection(Boolean)
Starts the local server or client using configured settings.
Declaration
public abstract bool StartConnection(bool server)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | server | True to start server. |
Returns
Type | Description |
---|---|
System.Boolean |
StopConnection(Boolean)
Stops the local server or client.
Declaration
public abstract bool StopConnection(bool server)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | server | True to stop server. |
Returns
Type | Description |
---|---|
System.Boolean |
StopConnection(Int32, Boolean)
Stops a remote client from the server, disconnecting the client.
Declaration
public abstract bool StopConnection(int connectionId, bool immediately)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | connectionId | ConnectionId of the client to disconnect. |
System.Boolean | immediately | True to abrutly stop the client socket. The technique used to accomplish immediate disconnects may vary depending on the transport. When not using immediate disconnects it's recommended to perform disconnects using the ServerManager rather than accessing the transport directly. |
Returns
Type | Description |
---|---|
System.Boolean |
Events
OnClientConnectionState
Called when a connection state changes for the local client.
Declaration
public abstract event Action<ClientConnectionStateArgs> OnClientConnectionState
Event Type
Type | Description |
---|---|
System.Action<ClientConnectionStateArgs> |
OnClientReceivedData
Called when the client receives data.
Declaration
public abstract event Action<ClientReceivedDataArgs> OnClientReceivedData
Event Type
Type | Description |
---|---|
System.Action<ClientReceivedDataArgs> |
OnRemoteConnectionState
Called when a connection state changes for a remote client.
Declaration
public abstract event Action<RemoteConnectionStateArgs> OnRemoteConnectionState
Event Type
Type | Description |
---|---|
System.Action<RemoteConnectionStateArgs> |
OnServerConnectionState
Called when a connection state changes for the local server.
Declaration
public abstract event Action<ServerConnectionStateArgs> OnServerConnectionState
Event Type
Type | Description |
---|---|
System.Action<ServerConnectionStateArgs> |
OnServerReceivedData
Called when the server receives data.
Declaration
public abstract event Action<ServerReceivedDataArgs> OnServerReceivedData
Event Type
Type | Description |
---|---|
System.Action<ServerReceivedDataArgs> |