class in UnityEngine.Networking
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.
CloseFor 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.
CloseThe NetworkServer uses a NetworkServerSimple for basic network functionality and adds more game-like functionality.
NetworkServer handles remote connections from remote clients via a NetworkServerSimple instance, and also has a local connection for a local client.
The NetworkServer is a singleton. It has static convenience functions such as NetworkServer.SendToAll() and NetworkServer.Spawn() which automatically use the singleton instance.
The NetworkManager uses the NetworkServer, but it can be used without the NetworkManager.
The set of networked objects that have been spawned is managed by NetworkServer. Objects are spawned with NetworkServer.Spawn() which adds them to this set, and makes them be created on clients. Spawned objects are removed automatically when they are destroyed, or than they can be removed from the spawned set by calling NetworkServer.UnSpawn() - this does not destroy the object.
There are a number of internal messages used by NetworkServer, these are setup when NetworkServer.Listen() is called.
active | Checks if the server has been started. |
connections | A list of all the current connections from clients. |
dontListen | If you enable this, the server will not listen for incoming connections on the regular network port. |
handlers | Dictionary of the message handlers registered with the server. |
hostTopology | The host topology that the server is using. |
listenPort | The port that the server is listening on. |
localClientActive | True is a local client is currently active on the server. |
localConnections | A list of local connections on the server. |
maxDelay | The maximum delay before sending packets on connections. |
networkConnectionClass | The class to be used when creating new network connections. |
numChannels | The number of channels the network is configure with. |
objects | This is a dictionary of networked objects that have been spawned on the server. |
serverHostId | The transport layer hostId used by this server. |
useWebSockets | This makes the server listen for WebSockets connections instead of normal transport layer connections. |
AddExternalConnection | This accepts a network connection from another external source and adds it to the server. |
AddPlayerForConnection | When an AddPlayer message handler has received a request from a player, the server calls this to associate the player object with the connection. |
BecomeHost | This allows a client that has been disconnected from a server, to become the host of a new version of the game. |
ClearHandlers | Clear all registered callback handlers. |
ClearLocalObjects | This 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. |
ClearSpawners | Clears all registered spawn prefab and spawn handler functions for this server. |
Configure | This configures the transport layer settings for the server. |
Destroy | Destroys this object and corresponding objects on all clients. |
DestroyPlayersForConnection | This destroys all the player objects associated with a NetworkConnections on a server. |
DisconnectAll | Disconnect all currently connected clients. |
FindLocalObject | This finds the local NetworkIdentity object with the specified network Id. |
GetConnectionStats | Gets aggregate packet stats for all connections. |
GetStatsIn | Get inbound network statistics for the server. |
GetStatsOut | Get outbound network statistics for the client. |
Listen | Start the server on the given port number. Note that if a match has been created, this will listen using the Relay server instead of a local socket. |
ListenRelay | Starts 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 match exists. |
RegisterHandler | Register a handler for a particular message type. |
RemoveExternalConnection | This removes an external connection added with AddExternalConnection(). |
ReplacePlayerForConnection | This replaces the player object for a connection with a different player object. The old player object is not destroyed. |
Reset | Reset the NetworkServer singleton. |
ResetConnectionStats | Resets the packet stats on all connections. |
SendByChannelToAll | Sends a network message to all connected clients on a specified transport layer QoS channel. |
SendByChannelToReady | Sends a network message to all connected clients that are "ready" on a specified transport layer QoS channel. |
SendBytesToPlayer | This sends an array of bytes to a specific player. |
SendBytesToReady | This sends an array of bytes to all ready players. |
SendToAll | Send a message structure with the given type number to all connected clients. |
SendToClient | Send a message to the client which owns the given connection ID. |
SendToClientOfPlayer | Send a message to the client which owns the given player object instance. |
SendToReady | Send a message structure with the given type number to only clients which are ready. |
SendUnreliableToAll | Send given message structure as an unreliable message to all connected clients. |
SendUnreliableToReady | Send given message structure as an unreliable message only to ready clients. |
SendWriterToReady | Sends the contents of a NetworkWriter object to the ready players. |
SetAllClientsNotReady | Marks all connected clients as no longer ready. |
SetClientNotReady | Sets the client of the connection to be not-ready. |
SetClientReady | Sets the client to be ready. |
SetNetworkConnectionClass | This sets the class used when creating new network connections. |
Shutdown | This shuts down the server and disconnects all clients. |
Spawn | Spawn the given game object on all clients which are ready. |
SpawnObjects | This causes NetworkIdentity objects in a scene to be spawned on a server. |
SpawnWithClientAuthority | This spawns an object like NetworkServer.Spawn() but also assigns Client Authority to the specified client. |
UnregisterHandler | Unregisters a handler for a particular message type. |
UnSpawn | This takes an object that has been spawned and un-spawns it. |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thanks for helping to make the Unity documentation better!