C# Class UnityEngine.Networking.NetworkConnection

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

Inheritance: IDisposable
ファイルを表示 Open project: CarlosHBC/UnityDecompiled Class Usage Examples

Public Properties

Property Type Description
address string
connectionId int
hostId int
isReady bool
lastMessageTime float
logNetworkMessages bool

Private Properties

Property Type Description
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

Public Methods

Method Description
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.

Protected Methods

Method Description
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.

Private Methods

Method Description
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

Method Details

CheckHandler() public method

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.
return bool

Disconnect() public method

Disconnects this connection.

public Disconnect ( ) : void
return void

Dispose() public method

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

public Dispose ( ) : void
return void

Dispose() protected method

protected Dispose ( bool disposing ) : void
disposing bool
return void

FlushChannels() public method

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

public FlushChannels ( ) : void
return void

GetStatsIn() public method

public GetStatsIn ( int &numMsgs, int &numBytes ) : void
numMsgs int
numBytes int
return void

GetStatsOut() public method

public GetStatsOut ( int &numMsgs, int &numBufferedMsgs, int &numBytes, int &lastBufferedPerSecond ) : void
numMsgs int
numBufferedMsgs int
numBytes int
lastBufferedPerSecond int
return void

HandleBytes() protected method

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.
return void

HandleReader() protected method

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.
return void

Initialize() public method

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.
return void

InvokeHandler() public method

This function invokes the registered handler function for a message.

public InvokeHandler ( NetworkMessage netMsg ) : bool
netMsg NetworkMessage The message object to process.
return bool

InvokeHandler() public method

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.
return bool

InvokeHandlerNoData() public method

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.
return bool

RegisterHandler() public method

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.
return void

ResetStats() public method

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

public ResetStats ( ) : void
return void

Send() public method

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.
return bool

SendByChannel() public method

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.
return bool

SendBytes() public method

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.
return bool

SendUnreliable() public method

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.
return bool

SendWriter() public method

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.
return bool

SetChannelOption() public method

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.
return bool

SetMaxDelay() public method

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

public SetMaxDelay ( float seconds ) : void
seconds float Time in seconds.
return void

ToString() public method

Returns a string representation of the NetworkConnection object state.

public ToString ( ) : string
return string

TransportRecieve() public method

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.
return void

TransportSend() public method

public TransportSend ( byte bytes, int numBytes, int channelId, byte &error ) : bool
bytes byte
numBytes int
channelId int
error byte
return bool

UnregisterHandler() public method

This removes the handler registered for a message Id.

public UnregisterHandler ( short msgType ) : void
msgType short The message ID to unregister.
return void

Property Details

address public_oe property

The IP address associated with the connection.

public string address
return string

connectionId public_oe property

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

public int connectionId
return int

hostId public_oe property

Transport level host ID for this connection.

public int hostId
return int

isReady public_oe property

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

public bool isReady
return bool

lastMessageTime public_oe property

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

public float lastMessageTime
return float

logNetworkMessages public_oe property

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

public bool logNetworkMessages
return bool