Legacy Documentation: Version 5.1
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

NetworkTransport

class in UnityEngine.Networking

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Description

Low level (transport layer) API.

Static Variables

IsStartedObsolete, will be removed.

Static Functions

AddHostWill create host (open socket) with given topology and port.
AddHostWithSimulatorWill create host (open socket) and configure them to simulate internet latency (works on editor and development build only).
AddWebsocketHostCreated web socket host. This function is supported only for Editor (Win, Linux, Mac) and StandalonePlayers (Win, Linux, Mac) Topology is used to define how many client can connect, and how many messages should be preallocated in send and receive pool, all other parameters are ignored.
ConnectTry to establish connection to other peer.
ConnectAsNetworkHostCreate dedicated connection to relay server.
ConnectEndPointTry to establish connection to other peer, where the peer is specified using a C# System.EndPoint.
ConnectToNetworkPeerCreate connection to other peer in the relay group.
ConnectWithSimulatorConnect with simulated latency.
DisconnectSend disconnect signal to peer and close connection. user should call Receive() to be notified that connection is closed. This signal will send only once (best effort delivery) iif this packet will dropped by some reason, peer will close connection by timeout.
DisconnectNetworkHostAplyed only for client which has been already owner of the same group of relay server. it will disconnect this owner from the group, group will be distracted or (if it supported) one of the member of this group should became new owner (owner migration).
FinishSendMulticastFunction will finalize sending message to group of connection. (only one multicast message per time is allowed for host).
GetAssetIdThe UNet spawning system uses assetIds to identify how spawn remote objects. This function allows you to get the assetId for the prefab associated with an object.
GetBroadcastConnectionInfoIf Receive() function returns BroadcastEvent, immedeately this function will return connection info of broadcast sender. This info can be used for connection to broadcast sender.
GetBroadcastConnectionMessageIf Receive() function returns BroadcastEvent, immedeately this function will return complimentary message of broadcast sender.
GetConnectionInfoReturn connection parameters of connected connection, this parameters can be sent to other user which can establish direct connection to this peer. If peer connected via relay, relay related parameters will be not invalid.
GetCurrentIncomingMessageAmountReturn value of messages waiting for reading.
GetCurrentOutgoingMessageAmountReturn total message amount waiting for sending.
GetCurrentRttReturn round trip time for connection.
GetNetIOTimeuSFunction returns time spent on network io operations in micro seconds.
GetNetworkTimestampGet UNET timestamp which can be added to message for further definitions of packet delaying.
GetPacketReceivedRateReturn current receive rate in bytes per sec.
GetPacketSentRateReurn outgoing rate in bytes per second.
GetRemoteDelayTimeMSReturn time delay for timestamp received from message (previously created by GetNetworkTimestamp()).
GetRemotePacketReceivedRateGet received rate in bytes per second for remote peer, comparison with local send rate can give information how many bytes was lost.
InitFirst function which should be called before any other NetworkTransport function.
IsBroadcastDiscoveryRunningCheck if broadcastdiscovery sender works.
ReceiveDelivered different network events to user. kConnectionEvent will notify about new connection established, kDisconnectEvent will report about disconnection happened, kDataEvent will report about new information delivered. Use must represent buffer for delivered data.
ReceiveFromHostSimilar to Receive() but will ask only provided host. It for example allows to mix server/client in the same game.
ReceiveRelayEventFromHostFunction delivered relay group event for group owner.
RemoveHostClose opened socket, close all connection belonging this socket.
SendSend data to peer.
SendMulticastFunction adds another connection to multy peer sends.
SetBroadcastCredentialsSet credentials for received broadcast message. If one of credentials is wrong, received brodcast discovery message will drop.
SetPacketStatUsed to inform the profiler of network packet statistics.
ShutdownShutdown the transport layer, after calling this function no any other function can be called.
StartBroadcastDiscoveryFunction starts send broadcasting message in all local subnets.
StartSendMulticastStart process sending message per group of connected connection.
StopBroadcastDiscoveryStop sending broadcast discovery message.