Select your preferred scripting language. All code snippets will be displayed in this language.
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.
Closebytes | 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:
no example available in JavaScript
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.
no example available in JavaScript
public class SpaceManager : NetworkManager {
void Start() { NetworkServer.NetworkConnectionClass = typeof(DebugConnection); NetworkClient.NetworkConnectionClass = typeof(DebugConnection); } }