Legacy Documentation: Version 5.1
LanguageEnglish
  • C#
  • JS

Script language

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

NetworkServer

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

High level UNET server.

Static Variables

activeChecks if the server has been started.
connectionsA list of all the current connections from clients.
handlersDictionary of the message handlers registered with the server.
localClientActiveTrue is a local client is currently active on the server.
localConnectionsA list of local connections on the server.
maxDelayThe maximum delay before sending packets on connections.
numChannelsThe number of channels the network is configure with.
objectsThis is a dictionary of networked objects that have been spawned on the server.
sendPeerInfoSetting this true will make the server send peer info to all participants of the network.

Public Functions

SendNetworkInfoThis sends information about all participants in the current network game to the connection.

Static Functions

AddPlayerForConnectionWhen a SYSTEM_ADD_PLAYER message handler has received a request from a player, the server should call this when he's created the player's object.
ClearHandlersClear all registered callback handlers.
ClearLocalObjectsThis clears all of the networked objects that the server is aware of. This can be required if a scene change deleted all of the objects without destroying them in the normal manner.
ClearSpawnersClears all registered spawn prefab and spawn handler functions for this server.
ConfigureConfigure the server with the given tuner and connection count.
DestroyDestroys this object and corresponding objects on all clients.
DestroyPlayersForConnectionThis destroys all the player objects associated with a NetworkConnections on a server.
DisconnectAllDisconnect all currently connected clients.
FindLocalObjectThis finds the NetworkIdentity game object that matches a netId.
GetConnectionStatsGets aggregate packet stats for all connections.
GetStatsInGet inbound network statistics for the server.
GetStatsOutGet outbound network statistics for the client.
ListenStart the server on the given port number. Note that if a UMatch has been created, this will list using the relay server in the UMatch.
ListenRelayUnderlyingModel.MemDoc.MemDocModelStarts a server using a relay server. This is the manual way of using the relay server, as the regular NetworkServer.Connect() will automatically use the relay server if a UMatch exists.
RegisterHandlerRegister a handler for a particular message type.
ReplacePlayerForConnectionThis replaces the player object for a connection with a different player object. The old player object is not destroyed.
ResetReset the NetworkServer singleton.
ResetConnectionStatsResets the packet stats on all connections.
SendByChannelToAllSend a message structure through the given channel to all connected clients.
SendByChannelToReadySend a message structure through the given channel to only clients which have sent the Ready signal.
SendBytesToPlayerThis sends an array of bytes to a specific player.
SendBytesToReadyThis sends an array of bytes to all ready players.
SendToAllSend a message structure with the given type number to all connected clients.
SendToClientSend a message to the client which owns the given connection ID.
SendToClientOfPlayerSend a message to the client which owns the given player object instance.
SendToReadySend a message structure with the given type number to only clients which are ready.
SendUnreliableToAllSend given message structure as an unreliable message to all connected clients.
SendUnreliableToReadySend given message structure as an unreliable message only to ready clients.
SendWriterToReadySends the contents of a NetworkWriter object to the ready players.
SetAllClientsNotReadyMarks all connected clients as no longer ready.
SetClientNotReadySets the client of the connection to be not-ready.
SetClientReadySets the client to be ready.
ShutdownThis shuts down the server and disconnects all clients.
SpawnSpawn the given game object on all clients which are ready.
SpawnObjectsThis causes NetworkIdentity objects in a scene to be spawned on a server.
UnregisterHandlerUnregisters a handler for a particular message type.