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

파라미터

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

반환

bool True if data was sent.

설명

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:

using UnityEngine;
using UnityEngine.Networking;
using System;
using System.Text;

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.

using UnityEngine;
using UnityEngine.Networking;

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