Version: 5.5
public bool TransportSend (byte[] bytes, int numBytes, int channelId, out byte error);

Parámetros

bytes Data to send.
numBytes Size of data to send.
channelId Channel to send data on.
error Error code for send.

Valor de retorno

bool True if data was sent.

Descripción

This virtual function allows custom network connection classes to process data send by the application before it goes to the network transport layer.

The default implementation of this function calls NetworkTransport.Send() with the supplied data, but custom implementations can pass modified versions of the data. This example logs the sent data to the console:

class DebugConnection : NetworkConnection
{
    public override bool TransportSend(byte[] bytes, int numBytes, int channelId, out byte error)
    {
        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("TransportSend    h:" + hostId + " con:" + connectionId + " bytes:" + numBytes + " " + msg);

return NetworkTransport.Send(hostId, connectionId, channelId, bytes, numBytes, out error); } }

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);
    }
}