Select your preferred scripting language. All code snippets will be displayed in this language.
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.
CloseThis is a network client class used by the networking system. It contains a NetworkConnection that is used to connection to a network server.
The NetworkClient handle connection state, messages handlers, and connection configuration. There can be many NetworkClient instances in a process at a time, but only one that is connected to a game server (NetworkServer) that uses spawned objects.
NetworkClient has an internal update function where it handles events from the transport layer. This includes asynchronous connect events, disconnect events and incoming data from a server.
The NetworkManager has a NetworkClient instance that it uses for games that it starts, but the NetworkClient may be used by itself.
active | True if a network client is currently active. |
allClients | A list of all the active network clients in the current process. |
connection | The NetworkConnection object this client is using. |
handlers | The registered network message handlers. |
hostPort | The local port that the network client uses to connect to the server. |
hostTopology | The host topology that this client is using. |
isConnected | This gives the current connection status of the client. |
networkConnectionClass | The class to use when creating new NetworkConnections. |
numChannels | The number of QoS channels currently configured for this client. |
serverIp | The IP address of the server that this client is connected to. |
serverPort | The port of the server that this client is connected to. |
NetworkClient | Creates a new NetworkClient instance. |
Configure | This configures the transport layer settings for a client. |
Connect | Connect client to a NetworkServer instance. |
ConnectWithSimulator | Connect client to a NetworkServer instance with simulated latency and packet loss. |
Disconnect | Disconnect from server. |
GetConnectionStats | Retrieves statistics about the network packets sent on this connection. |
GetRTT | Gets the Return Trip Time for this connection. |
GetStatsIn | Get inbound network statistics for the client. |
GetStatsOut | Get outbound network statistics for the client. |
ReconnectToNewHost | This is used by a client that has lost the connection to the old host, to reconnect to the new host of a game. |
RegisterHandler | Register a handler for a particular message type. |
ResetConnectionStats | Resets the statistics return by NetworkClient.GetConnectionStats() to zero values. |
Send | This sends a network message with a message Id to the server. This message is sent on channel zero, which by default is the reliable channel. |
SendByChannel | This sends a network message with a message Id to the server on a specific channel. |
SendBytes | This sends the data in an array of bytes to the server that the client is connected to. |
SendUnreliable | This sends a network message with a message Id to the server on channel one, which by default is the unreliable channel. |
SendWriter | This sends the contents of the NetworkWriter's buffer to the connected server on the specified channel. |
SetMaxDelay | Set the maximum amount of time that can pass for transmitting the send buffer. |
SetNetworkConnectionClass | This sets the class that is used when creating new network connections. |
Shutdown | Shut down a client. |
UnregisterHandler | Unregisters a network message handler. |
GetTotalConnectionStats | Retrieves statistics about the network packets sent on all connections. |
ShutdownAll | Shuts down all network clients. |
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!