Legacy Documentation: Version 5.1
LanguageEnglish
  • C#
  • JS

Script language

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

NetworkClient

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 client.

It can be used to connect to a high level UNET server instance (NetworkServer).

Static Variables

activeTrue if a network client is currently active.
allClientsA list of all the active network clients.

Variables

connectionThe NetworkConnection object this client is using.
handlersThe registered network message handlers.
isConnectedThis gives the current connection status of the client.
numChannelsThe number of QoS channels currently configured for this client.
peersThe other network participants in the current game.
serverIpThe IP address of the server that this client is connected to.
serverPortThe port of the server that this client is connected to.

Constructors

NetworkClientCreates a new NetworkClient instance.

Public Functions

ConfigureConfigure the client instance with the given tuner and connection count.
ConnectConnect client to a NetworkServer instance.
ConnectWithSimulatorConnect client to a NetworkServer instance with simulated latency and packet loss.
DisconnectDisconnect from server.
GetConnectionStatsRetrieves statistics about the network packets sent on this connection.
GetRTTGets the Return Trip Time for this connection.
GetStatsInGet inbound network statistics for the client.
GetStatsOutGet outbound network statistics for the client.
RegisterHandlerRegister a handler for a particular message type.
ResetConnectionStatsResets the statistics return by NetworkClient.GetConnectionStats() to zero values.
SendSends a network message to the connected server. The contents can be a message object - which will be automatically serialized, or it can be a MemoryStream containing serialized data.The message ID determines the handler that will be called on the server for this message.
SendByChannelSend a message structure through the given channel.
SendBytesThis sends the data in an array of bytes to the server that the client is connected to.
SendUnreliableSend given message structure as an unreliable message.
SendWriterThis sends the contents of the NetworkWriter's buffer to the connected server.
SetMaxDelaySet the maximum amount of time that can pass for transmitting the send buffer.
ShutdownShut down a client.
UnregisterHandlerUnregisters a network message handler.

Static Functions

GetTotalConnectionStatsRetrieves statistics about the network packets sent on all connections.
ShutdownAllShuts down all network clients.