Version: 2017.2
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); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961