public void TransportRecieve (byte[] bytes, int numBytes, int channelId);

Parámetros

bytes The data recieved.
numBytes The size of the data recieved.
channelId The channel that the data was received on.

Descripción

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

The default implementation of this function calls HandleBytes() on the received data. Custom implmentations can also use HandleBytes(), but can pass modified versions of the data received or other data.

This example logs the data received to the console, then passes it to HandleBytes.

class DebugConnection : NetworkConnection
{
    public override void TransportRecieve(byte[] bytes, int numBytes, int channelId)
    {
        StringBuilder msg = new StringBuilder();
        for (int i = 0; i < numBytes; i++)
        {
            var s = String.Format("{0:X2}", bytes[i]);
            msg.Append(s);
            if (i > 50) break;
        }
        UnityEngine.Debug.LogError("TransportRecieve h:" + hostId + " con:" + connectionId + " bytes:" + numBytes + " " + msg);

HandleBytes(bytes, numBytes, channelId); } }

Other uses for this function could be data compression or data encryption.

Custom network connection classes are used by setting NetworkServer.NetworkConnectionClass and NetworkClient.NetworkConnectionClass.

public class SpaceManager : NetworkManager
{
    void Start()
    {
        NetworkServer.NetworkConnectionClass = typeof(DebugConnection);
        NetworkClient.NetworkConnectionClass = typeof(DebugConnection);
    }
}