Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

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

Network

Namespace: 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

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

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 Variables

connections All connected players.
connectionTesterIP The IP address of the connection tester used in Network.TestConnection.
connectionTesterPort The port of the connection tester used in Network.TestConnection.
incomingPassword Set the password for the server (for incoming connections).
isClient Returns true if your peer type is client.
isMessageQueueRunning Enable or disable the processing of network messages.
isServer Returns true if your peer type is server.
logLevel Set the log level for network messages (default is Off).
maxConnections Set the maximum amount of connections/players allowed.
minimumAllocatableViewIDs Get or set the minimum number of ViewID numbers in the ViewID pool given to clients by the server.
natFacilitatorIP The IP address of the NAT punchthrough facilitator.
natFacilitatorPort The port of the NAT punchthrough facilitator.
peerType The status of the peer type, i.e. if it is disconnected, connecting, server or client.
player Get the local NetworkPlayer instance.
proxyIP The IP address of the proxy server.
proxyPassword Set the proxy server password.
proxyPort The port of the proxy server.
sendRate The default send rate of network updates for all Network Views.
time Get the current network time (seconds).
useProxy Indicate if proxy support is needed, in which case traffic is relayed through the proxy server.

Static Functions

AllocateViewID Query for the next available network view ID number and allocate it (reserve).
CloseConnection Close the connection to another system.
Connect Connect to the specified host (ip or domain name) and server port.
Destroy Destroy the object associated with this view ID across the network.
DestroyPlayerObjects Destroy all the objects based on view IDs belonging to this player.
Disconnect Close all open connections and shuts down the network interface.
GetAveragePing The last average ping time to the given player in milliseconds.
GetLastPing The last ping time to the given player in milliseconds.
HavePublicAddress Check if this machine has a public IP address.
InitializeSecurity Initializes security layer.
InitializeServer Initialize the server.
Instantiate Network instantiate a prefab.
RemoveRPCs Remove all RPC functions which belong to this player ID.
RemoveRPCsInGroup Remove all RPC functions which belong to given group number.
SetLevelPrefix Set the level prefix which will then be prefixed to all network ViewID numbers.
SetReceivingEnabled Enable or disables the reception of messages in a specific group number from a specific player.
SetSendingEnabled Enables or disables transmission of messages and RPC calls on a specific network group number.
TestConnection Test this machines network connection.
TestConnectionNAT Test the connecction specifically for NAT punchthrough connectivity.

Messages

OnConnectedToServer Called on the client when you have successfully connected to a server.
OnDisconnectedFromServer Called on client during disconnection from server, but also on the server when the connection has disconnected.
OnFailedToConnect Called on the client when a connection attempt fails for some reason.
OnNetworkInstantiate Called on objects which have been network instantiated with Network.Instantiate.
OnPlayerConnected Called on the server whenever a new player has successfully connected.
OnPlayerDisconnected Called on the server whenever a player is disconnected from the server.
OnSerializeNetworkView Used to customize synchronization of variables in a script watched by a network view.
OnServerInitialized Called on the server whenever a Network.InitializeServer was invoked and has completed.