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

パラメーター

bytes送信するデータ
numBytes送信するデータのサイズ
channelIdデータを送信するチャンネル
error送信のエラーコード

戻り値

bool データが送信された場合、True を返します。

説明

この仮想関数はネットワークトランスポートレイヤーに行く前にカスタムのネットワーク接続クラスがアプリケーションによって送信されたデータを処理するを許可します。

この関数のデフォルトの実装は提供されたデータと NetworkTransport.Send() を呼び出しますが、カスタム実装は変更されたバージョンのデータを渡すことができます。この例はコンソールに送信されたデータを記録します。

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

この関数の他の用途にはデータ圧縮やデータ暗号化があります。

カスタムネットワーク接続クラスは NetworkServer.NetworkConnectionClass と 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