Version: 2017.4
LanguageEnglish
  • C#
  • JS

Script language

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

Network

class in UnityEngine

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

Submission failed

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

Close

Cancel

Description

The network class is at the heart of the network implementation and provides the core functions.

This class configures the network interface and all the network parameters. You use it to set up a server or connect to one and have a row of helper functions to help you with those tasks. For more information on what is exposed in the editor see the Network Manger component reference.

Static Properties

connectionsAll connected players.
connectionTesterIPThe IP address of the connection tester used in Network.TestConnection.
connectionTesterPortThe port of the connection tester used in Network.TestConnection.
incomingPasswordSet the password for the server (for incoming connections).
isClientReturns true if your peer type is client.
isMessageQueueRunningEnable or disable the processing of network messages.
isServerReturns true if your peer type is server.
logLevelSet the log level for network messages (default is Off).
maxConnectionsSet the maximum amount of connections/players allowed.
minimumAllocatableViewIDsGet or set the minimum number of ViewID numbers in the ViewID pool given to clients by the server.
natFacilitatorIPThe IP address of the NAT punchthrough facilitator.
natFacilitatorPortThe port of the NAT punchthrough facilitator.
peerTypeThe status of the peer type, i.e. if it is disconnected, connecting, server or client.
playerGet the local NetworkPlayer instance.
proxyIPThe IP address of the proxy server.
proxyPasswordSet the proxy server password.
proxyPortThe port of the proxy server.
sendRateThe default send rate of network updates for all Network Views.
timeGet the current network time (seconds).
useProxyIndicate if proxy support is needed, in which case traffic is relayed through the proxy server.

Static Methods

AllocateViewIDQuery for the next available network view ID number and allocate it (reserve).
CloseConnectionClose the connection to another system.
ConnectConnect to the specified host (ip or domain name) and server port.
DestroyDestroy the object associated with this view ID across the network.
DestroyPlayerObjectsDestroy all the objects based on view IDs belonging to this player.
DisconnectClose all open connections and shuts down the network interface.
GetAveragePingThe last average ping time to the given player in milliseconds.
GetLastPingThe last ping time to the given player in milliseconds.
HavePublicAddressCheck if this machine has a public IP address.
InitializeSecurityInitializes security layer.
InitializeServerInitialize the server.
InstantiateNetwork instantiate a prefab.
RemoveRPCsRemove all RPC functions which belong to this player ID.
RemoveRPCsInGroupRemove all RPC functions which belong to given group number.
SetLevelPrefixSet the level prefix which will then be prefixed to all network ViewID numbers.
SetReceivingEnabledEnable or disables the reception of messages in a specific group number from a specific player.
SetSendingEnabledEnables or disables transmission of messages and RPC calls on a specific network group number.
TestConnectionTest this machines network connection.
TestConnectionNATTest the connection specifically for NAT punch-through connectivity.

Messages

OnConnectedToServerCalled on the client when you have successfully connected to a server.
OnDisconnectedFromServerCalled on client during disconnection from server, but also on the server when the connection has disconnected.
OnFailedToConnectCalled on the client when a connection attempt fails for some reason.
OnNetworkInstantiateCalled on objects which have been network instantiated with Network.Instantiate.
OnPlayerConnectedCalled on the server whenever a new player has successfully connected.
OnPlayerDisconnectedCalled on the server whenever a player is disconnected from the server.
OnSerializeNetworkViewUsed to customize synchronization of variables in a script watched by a network view.
OnServerInitializedCalled on the server whenever a Network.InitializeServer was invoked and has completed.