Legacy Documentation: Version 5.3
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

Description

Low level (transport layer) API.

Static Functions

AddHostWill create a host (open socket) with given topology and optionally port and IP.
AddHostWithSimulatorCreate a 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 another 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.
GetNetworkLostPacketNumReturn total number of packets has been lost from start.
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()).
InitFirst function which should be called before any other NetworkTransport function.
IsBroadcastDiscoveryRunningCheck if broadcastdiscovery sender works.
ReceiveDeliver network events to user.
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.
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.