C# Класс UnityEngine.Networking.NetworkConnection

A High level network connection. This is used for connections from client-to-server and for connection from server-to-client.

Наследование: IDisposable
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
address string
connectionId int
hostId int
isReady bool
lastMessageTime float
logNetworkMessages bool

Private Properties

Свойство Тип Описание
AddOwnedObject void
AddToVisList void
CheckChannel bool
GetPlayerController bool
HandleFragment void
IsReliableQoS bool
IsSequencedQoS bool
LogSend void
OnFragment void
RemoveFromVisList void
RemoveObservers void
RemoveOwnedObject void
RemovePlayerController void
SetHandlers void
SetPlayerController void

Открытые методы

Метод Описание
CheckHandler ( short msgType ) : bool

This function checks if there is a message handler registered for the message ID.

Disconnect ( ) : void

Disconnects this connection.

Dispose ( ) : void

Disposes of this connection, releasing channel buffers that it holds.

FlushChannels ( ) : void

This causes the channels of the network connection to flush their data to the transport layer.

GetStatsIn ( int &numMsgs, int &numBytes ) : void
GetStatsOut ( int &numMsgs, int &numBufferedMsgs, int &numBytes, int &lastBufferedPerSecond ) : void
Initialize ( string networkAddress, int networkHostId, int networkConnectionId, HostTopology hostTopology ) : void

This inializes the internal data structures of a NetworkConnection object, including channel buffers.

InvokeHandler ( NetworkMessage netMsg ) : bool

This function invokes the registered handler function for a message.

InvokeHandler ( short msgType, NetworkReader reader, int channelId ) : bool

This function invokes the registered handler function for a message.

InvokeHandlerNoData ( short msgType ) : bool

This function invokes the registered handler function for a message, without any message data.

RegisterHandler ( short msgType, NetworkMessageDelegate handler ) : void

This registers a handler function for a message Id.

ResetStats ( ) : void

Resets the statistics that are returned from NetworkClient.GetConnectionStats().

Send ( short msgType, MessageBase msg ) : bool

This sends a network message with a message ID on the connection. This message is sent on channel zero, which by default is the reliable channel.

SendByChannel ( short msgType, MessageBase msg, int channelId ) : bool

This sends a network message on the connection using a specific transport layer channel.

SendBytes ( byte bytes, int numBytes, int channelId ) : bool

This sends an array of bytes on the connection.

SendUnreliable ( short msgType, MessageBase msg ) : bool

This sends a network message with a message ID on the connection. This message is sent on channel one, which by default is the unreliable channel.

SendWriter ( NetworkWriter writer, int channelId ) : bool

This sends the contents of a NetworkWriter object on the connection.

SetChannelOption ( int channelId, ChannelOption option, int value ) : bool

This sets an option on the network channel.

SetMaxDelay ( float seconds ) : void

The maximum time in seconds that messages are buffered before being sent.

ToString ( ) : string

Returns a string representation of the NetworkConnection object state.

TransportRecieve ( byte bytes, int numBytes, int channelId ) : void

This virtual function allows custom network connection classes to process data from the network before it is passed to the application.

TransportSend ( byte bytes, int numBytes, int channelId, byte &error ) : bool
UnregisterHandler ( short msgType ) : void

This removes the handler registered for a message Id.

Защищенные методы

Метод Описание
Dispose ( bool disposing ) : void
HandleBytes ( byte buffer, int receivedSize, int channelId ) : void

This makes the connection process the data contained in the buffer, and call handler functions.

HandleReader ( NetworkReader reader, int receivedSize, int channelId ) : void

This makes the connection process the data contained in the stream, and call handler functions.

Приватные методы

Метод Описание
AddOwnedObject ( NetworkIdentity obj ) : void
AddToVisList ( NetworkIdentity uv ) : void
CheckChannel ( int channelId ) : bool
GetPlayerController ( short playerControllerId, PlayerController &playerController ) : bool
HandleFragment ( NetworkReader reader, int channelId ) : void
IsReliableQoS ( QosType qos ) : bool
IsSequencedQoS ( QosType qos ) : bool
LogSend ( byte bytes ) : void
OnFragment ( NetworkMessage netMsg ) : void
RemoveFromVisList ( NetworkIdentity uv, bool isDestroyed ) : void
RemoveObservers ( ) : void
RemoveOwnedObject ( NetworkIdentity obj ) : void
RemovePlayerController ( short playerControllerId ) : void
SetHandlers ( NetworkMessageHandlers handlers ) : void
SetPlayerController ( PlayerController player ) : void

Описание методов

CheckHandler() публичный Метод

This function checks if there is a message handler registered for the message ID.

public CheckHandler ( short msgType ) : bool
msgType short The message ID of the handler to look for.
Результат bool

Disconnect() публичный Метод

Disconnects this connection.

public Disconnect ( ) : void
Результат void

Dispose() публичный Метод

Disposes of this connection, releasing channel buffers that it holds.

public Dispose ( ) : void
Результат void

Dispose() защищенный Метод

protected Dispose ( bool disposing ) : void
disposing bool
Результат void

FlushChannels() публичный Метод

This causes the channels of the network connection to flush their data to the transport layer.

public FlushChannels ( ) : void
Результат void

GetStatsIn() публичный Метод

public GetStatsIn ( int &numMsgs, int &numBytes ) : void
numMsgs int
numBytes int
Результат void

GetStatsOut() публичный Метод

public GetStatsOut ( int &numMsgs, int &numBufferedMsgs, int &numBytes, int &lastBufferedPerSecond ) : void
numMsgs int
numBufferedMsgs int
numBytes int
lastBufferedPerSecond int
Результат void

HandleBytes() защищенный Метод

This makes the connection process the data contained in the buffer, and call handler functions.

protected HandleBytes ( byte buffer, int receivedSize, int channelId ) : void
buffer byte Data to process.
receivedSize int Size of the data to process.
channelId int Channel the data was recieved on.
Результат void

HandleReader() защищенный Метод

This makes the connection process the data contained in the stream, and call handler functions.

protected HandleReader ( NetworkReader reader, int receivedSize, int channelId ) : void
reader NetworkReader Stream that contains data.
receivedSize int Size of the data.
channelId int Channel the data was received on.
Результат void

Initialize() публичный Метод

This inializes the internal data structures of a NetworkConnection object, including channel buffers.

public Initialize ( string networkAddress, int networkHostId, int networkConnectionId, HostTopology hostTopology ) : void
networkAddress string The host or IP connected to.
networkHostId int The transport hostId for the connection.
networkConnectionId int The transport connectionId for the connection.
hostTopology HostTopology The topology to be used.
Результат void

InvokeHandler() публичный Метод

This function invokes the registered handler function for a message.

public InvokeHandler ( NetworkMessage netMsg ) : bool
netMsg NetworkMessage The message object to process.
Результат bool

InvokeHandler() публичный Метод

This function invokes the registered handler function for a message.

public InvokeHandler ( short msgType, NetworkReader reader, int channelId ) : bool
msgType short The message type of the handler to use.
reader NetworkReader The stream to read the contents of the message from.
channelId int The channel that the message arrived on.
Результат bool

InvokeHandlerNoData() публичный Метод

This function invokes the registered handler function for a message, without any message data.

public InvokeHandlerNoData ( short msgType ) : bool
msgType short The message ID of the handler to invoke.
Результат bool

RegisterHandler() публичный Метод

This registers a handler function for a message Id.

public RegisterHandler ( short msgType, NetworkMessageDelegate handler ) : void
msgType short The message ID to register.
handler NetworkMessageDelegate The handler function to register.
Результат void

ResetStats() публичный Метод

Resets the statistics that are returned from NetworkClient.GetConnectionStats().

public ResetStats ( ) : void
Результат void

Send() публичный Метод

This sends a network message with a message ID on the connection. This message is sent on channel zero, which by default is the reliable channel.

public Send ( short msgType, MessageBase msg ) : bool
msgType short The ID of the message to send.
msg MessageBase The message to send.
Результат bool

SendByChannel() публичный Метод

This sends a network message on the connection using a specific transport layer channel.

public SendByChannel ( short msgType, MessageBase msg, int channelId ) : bool
msgType short The message ID to send.
msg MessageBase The message to send.
channelId int The transport layer channel to send on.
Результат bool

SendBytes() публичный Метод

This sends an array of bytes on the connection.

public SendBytes ( byte bytes, int numBytes, int channelId ) : bool
bytes byte The array of data to be sent.
numBytes int The number of bytes in the array to be sent.
channelId int The transport channel to send on.
Результат bool

SendUnreliable() публичный Метод

This sends a network message with a message ID on the connection. This message is sent on channel one, which by default is the unreliable channel.

public SendUnreliable ( short msgType, MessageBase msg ) : bool
msgType short The message ID to send.
msg MessageBase The message to send.
Результат bool

SendWriter() публичный Метод

This sends the contents of a NetworkWriter object on the connection.

public SendWriter ( NetworkWriter writer, int channelId ) : bool
writer NetworkWriter A writer object containing data to send.
channelId int The transport channel to send on.
Результат bool

SetChannelOption() публичный Метод

This sets an option on the network channel.

public SetChannelOption ( int channelId, ChannelOption option, int value ) : bool
channelId int The channel the option will be set on.
option ChannelOption The option to set.
value int The value for the option.
Результат bool

SetMaxDelay() публичный Метод

The maximum time in seconds that messages are buffered before being sent.

public SetMaxDelay ( float seconds ) : void
seconds float Time in seconds.
Результат void

ToString() публичный Метод

Returns a string representation of the NetworkConnection object state.

public ToString ( ) : string
Результат string

TransportRecieve() публичный Метод

This virtual function allows custom network connection classes to process data from the network before it is passed to the application.

public TransportRecieve ( byte bytes, int numBytes, int channelId ) : void
bytes byte The data recieved.
numBytes int The size of the data recieved.
channelId int The channel that the data was received on.
Результат void

TransportSend() публичный Метод

public TransportSend ( byte bytes, int numBytes, int channelId, byte &error ) : bool
bytes byte
numBytes int
channelId int
error byte
Результат bool

UnregisterHandler() публичный Метод

This removes the handler registered for a message Id.

public UnregisterHandler ( short msgType ) : void
msgType short The message ID to unregister.
Результат void

Описание свойств

address публичное свойство

The IP address associated with the connection.

public string address
Результат string

connectionId публичное свойство

Unique identifier for this connection that is assigned by the transport layer.

public int connectionId
Результат int

hostId публичное свойство

Transport level host ID for this connection.

public int hostId
Результат int

isReady публичное свойство

Flag that tells if the connection has been marked as "ready" by a client calling ClientScene.Ready().

public bool isReady
Результат bool

lastMessageTime публичное свойство

The last time that a message was received on this connection.

public float lastMessageTime
Результат float

logNetworkMessages публичное свойство

Setting this to true will log the contents of network message to the console.

public bool logNetworkMessages
Результат bool