Legacy Documentation: Version 2018.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

NetworkConnection.TransportReceive

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public method TransportReceive(bytes: byte[], numBytes: int, channelId: int): void;
public void TransportReceive(byte[] bytes, int numBytes, int channelId);

Parameters

bytesThe data recieved.
numBytesThe size of the data recieved.
channelIdThe channel that the data was received on.

Description

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.

no example available in JavaScript
using UnityEngine;
using UnityEngine.Networking;
using System;
using System.Text;

public class DebugConnection : NetworkConnection { public override void TransportReceive(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("TransportReceive 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.

no example available in JavaScript
using UnityEngine;
using UnityEngine.Networking;

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

Did you find this page useful? Please give it a rating: