Class UnityTransport
The Netcode for GameObjects NetworkTransport for UnityTransport. Note: This is highly recommended to use over UNet.
#
InheritanceSystem.Object
NetworkTransport
UnityTransport
#
ImplementsINetworkStreamDriverConstructor
#
Inherited MembersNetworkTransport.IsSupported
NetworkTransport.OnTransportEvent
NetworkTransport.InvokeOnTransportEvent(NetworkEvent, UInt64, ArraySegment\<Byte>, Single)
#
Namespace: Unity.Netcode.Transports.UTP#
Assembly: MLAPI.dll#
Syntax#
Fields#
ConnectionDataThe connection (address) data for this UnityTransport instance. This is where you can change IP Address, Port, or server's listen address. UnityTransport.ConnectionAddressData
#
Declaration#
Field ValueType | Description |
---|---|
UnityTransport.ConnectionAddressData |
#
DebugSimulatorCan be used to simulate poor network conditions such as:
- packet delay/latency
- packet jitter (variances in latency, see: https://en.wikipedia.org/wiki/Jitter)
- packet drop rate (packet loss)
#
Declaration#
Field ValueType | Description |
---|---|
UnityTransport.SimulatorParameters |
#
InitialMaxPacketQueueSizeThe default maximum (receive) packet queue size
#
Declaration#
Field ValueType | Description |
---|---|
System.Int32 |
#
InitialMaxPayloadSizeThe default maximum payload size
#
Declaration#
Field ValueType | Description |
---|---|
System.Int32 |
#
InitialMaxSendQueueSizeThe default maximum send queue size
#
Declaration#
Field ValueType | Description |
---|---|
System.Int32 |
#
s_DriverConstructorThe global INetworkStreamDriverConstructor implementation
#
Declaration#
Field ValueType | Description |
---|---|
INetworkStreamDriverConstructor |
#
Properties#
ConnectTimeoutMSTimeout in milliseconds indicating how long we will wait until we send a new connection attempt.
#
Declaration#
Property ValueType | Description |
---|---|
System.Int32 |
#
DisconnectTimeoutMSInactivity timeout after which a connection will be disconnected.
#
Declaration#
Property ValueType | Description |
---|---|
System.Int32 |
#
RemarksThe connection needs to receive data from the connected endpoint within this timeout. Note that with heartbeats enabled, simply not sending any data will not be enough to trigger this timeout (since heartbeats count as connection events).
#
DriverConstructorReturns either the global INetworkStreamDriverConstructor implementation or the current UnityTransport instance
#
Declaration#
Property ValueType | Description |
---|---|
INetworkStreamDriverConstructor |
#
HeartbeatTimeoutMSTimeout in milliseconds after which a heartbeat is sent if there is no activity.
#
Declaration#
Property ValueType | Description |
---|---|
System.Int32 |
#
MaxConnectAttemptsThe maximum amount of connection attempts we will try before disconnecting.
#
Declaration#
Property ValueType | Description |
---|---|
System.Int32 |
#
MaxPacketQueueSizeThe maximum amount of packets that can be in the internal send/receive queues.
#
Declaration#
Property ValueType | Description |
---|---|
System.Int32 |
#
RemarksBasically this is how many packets can be sent/received in a single update/frame.
#
MaxPayloadSizeThe maximum size of a payload that can be handled by the transport.
#
Declaration#
Property ValueType | Description |
---|---|
System.Int32 |
#
MaxSendQueueSizeThe maximum size in bytes of the transport send queue.
#
Declaration#
Property ValueType | Description |
---|---|
System.Int32 |
#
RemarksThe send queue accumulates messages for batching and stores messages when other internal send queues are full. If you routinely observe an error about too many in-flight packets, try increasing this.
#
ProtocolThe current ProtocolType used by the transport
#
Declaration#
Property ValueType | Description |
---|---|
UnityTransport.ProtocolType |
#
ServerClientIdThe client id used to represent the server.
#
Declaration#
Property ValueType | Description |
---|---|
System.UInt64 |
#
OverridesNetworkTransport.ServerClientId
#
Methods#
CreateDriver(UnityTransport, out NetworkDriver, out NetworkPipeline, out NetworkPipeline, out NetworkPipeline)Creates the internal NetworkDriver
#
Declaration#
ParametersType | Name | Description |
---|---|---|
UnityTransport | transport | The owner transport |
NetworkDriver | driver | The driver |
NetworkPipeline | unreliableFragmentedPipeline | The UnreliableFragmented NetworkPipeline |
NetworkPipeline | unreliableSequencedFragmentedPipeline | The UnreliableSequencedFragmented NetworkPipeline |
NetworkPipeline | reliableSequencedPipeline | The ReliableSequenced NetworkPipeline |
#
DisconnectLocalClient()Disconnects the local client from the remote
#
Declaration#
OverridesNetworkTransport.DisconnectLocalClient()
#
DisconnectRemoteClient(UInt64)Disconnects a remote client from the server
#
Declaration#
ParametersType | Name | Description |
---|---|---|
System.UInt64 | clientId | The client to disconnect |
#
OverridesNetworkTransport.DisconnectRemoteClient(UInt64)
#
GetCurrentRtt(UInt64)Gets the current RTT for a specific client
#
Declaration#
ParametersType | Name | Description |
---|---|---|
System.UInt64 | clientId | The client RTT to get |
#
ReturnsType | Description |
---|---|
System.UInt64 | The RTT |
#
OverridesNetworkTransport.GetCurrentRtt(UInt64)
#
Initialize(NetworkManager)Initializes the transport
#
Declaration#
ParametersType | Name | Description |
---|---|---|
NetworkManager | networkManager | The NetworkManager that initialized and owns the transport |
#
OverridesNetworkTransport.Initialize(NetworkManager)
#
PollEvent(out UInt64, out ArraySegment\<Byte>, out Single)Polls for incoming events, with an extra output parameter to report the precise time the event was received.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
System.UInt64 | clientId | The clientId this event is for |
System.ArraySegment\<System.Byte> | payload | The incoming data payload |
System.Single | receiveTime | The time the event was received, as reported by Time.realtimeSinceStartup. |
#
ReturnsType | Description |
---|---|
NetworkEvent | Returns the event type |
#
OverridesNetworkTransport.PollEvent(out UInt64, out ArraySegment\<Byte>, out Single)
#
Send(UInt64, ArraySegment\<Byte>, NetworkDelivery)Send a payload to the specified clientId, data and networkDelivery.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
System.UInt64 | clientId | The clientId to send to |
System.ArraySegment\<System.Byte> | payload | The data to send |
NetworkDelivery | networkDelivery | The delivery type (QoS) to send data with |
#
OverridesNetworkTransport.Send(UInt64, ArraySegment\<Byte>, NetworkDelivery)
#
SetClientRelayData(String, UInt16, Byte[], Byte[], Byte[], Byte[], Boolean)Set the relay server data for the host.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
System.String | ipAddress | IP address of the relay server. |
System.UInt16 | port | UDP port of the relay server. |
System.Byte[] | allocationId | Allocation ID as a byte array. |
System.Byte[] | key | Allocation key as a byte array. |
System.Byte[] | connectionData | Connection data as a byte array. |
System.Byte[] | hostConnectionData | Host's connection data as a byte array. |
System.Boolean | isSecure | Whether the connection is secure (uses DTLS). |
#
SetConnectionData(NetworkEndPoint, NetworkEndPoint)Sets IP and Port information. This will be ignored if using the Unity Relay and you should call SetRelayServerData(String, UInt16, Byte[], Byte[], Byte[], Byte[], Boolean)
#
Declaration#
ParametersType | Name | Description |
---|---|---|
NetworkEndPoint | endPoint | The remote end point |
NetworkEndPoint | listenEndPoint | The local listen endpoint |
#
SetConnectionData(String, UInt16, String)Sets IP and Port information. This will be ignored if using the Unity Relay and you should call SetRelayServerData(String, UInt16, Byte[], Byte[], Byte[], Byte[], Boolean)
#
Declaration#
ParametersType | Name | Description |
---|---|---|
System.String | ipv4Address | The remote IP address |
System.UInt16 | port | The remote port |
System.String | listenAddress | The local listen address |
#
SetDebugSimulatorParameters(Int32, Int32, Int32)Set the parameters for the debug simulator.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
System.Int32 | packetDelay | Packet delay in milliseconds. |
System.Int32 | packetJitter | Packet jitter in milliseconds. |
System.Int32 | dropRate | Packet drop percentage. |
#
SetHostRelayData(String, UInt16, Byte[], Byte[], Byte[], Boolean)Set the relay server data for the host.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
System.String | ipAddress | IP address of the relay server. |
System.UInt16 | port | UDP port of the relay server. |
System.Byte[] | allocationId | Allocation ID as a byte array. |
System.Byte[] | key | Allocation key as a byte array. |
System.Byte[] | connectionData | Connection data as a byte array. |
System.Boolean | isSecure | Whether the connection is secure (uses DTLS). |
#
SetRelayServerData(String, UInt16, Byte[], Byte[], Byte[], Byte[], Boolean)Set the relay server data for the server.
#
Declaration#
ParametersType | Name | Description |
---|---|---|
System.String | ipv4Address | IP address of the relay server. |
System.UInt16 | port | UDP port of the relay server. |
System.Byte[] | allocationIdBytes | Allocation ID as a byte array. |
System.Byte[] | keyBytes | Allocation key as a byte array. |
System.Byte[] | connectionDataBytes | Connection data as a byte array. |
System.Byte[] | hostConnectionDataBytes | The HostConnectionData as a byte array. |
System.Boolean | isSecure | Whether the connection is secure (uses DTLS). |
#
Shutdown()Shuts down the transport
#
Declaration#
OverridesNetworkTransport.Shutdown()
#
StartClient()Connects client to the server Note: When this method returns false it could mean:
- You are trying to start a client that is already started
- It failed during the initial port binding when attempting to begin to connect
#
Declaration#
ReturnsType | Description |
---|---|
System.Boolean | true if the client was started and false if it failed to start the client |
#
OverridesNetworkTransport.StartClient()
#
StartServer()Starts to listening for incoming clients Note: When this method returns false it could mean:
- You are trying to start a client that is already started
- It failed during the initial port binding when attempting to begin to connect
#
Declaration#
ReturnsType | Description |
---|---|
System.Boolean | true if the server was started and false if it failed to start the server |
#
OverridesNetworkTransport.StartServer()
#
ImplementsINetworkStreamDriverConstructor