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.

GlobalConfig.NetworkEventAvailable

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 var NetworkEventAvailable: Action<int>;
public Action<int> NetworkEventAvailable;

Description

Defines the callback delegate which you can use to get a notification when the host (defined by hostID) has a network event. The callback is called for all event types except NetworkEventType.Nothing.

See Also: NetworkEventType

This callback will be called from the IO thread. If you execute a long operation from this callback it will affect your IO operation performance, therefore you should return from these operations as soon as possible.

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

public class Test : MonoBehaviour { static int receiveCallbackOld = 0; static int receiveCallbackNew = 0; static int recHostId = -1;

//... public static void ReceiveCallback(int hostId) { ++receiveCallbackNew; //Notify main thread that ReceiveFromHost(hostId, ...) should be called, because there is incoming event waiting to read recHostId = hostId; }

void Start() { GlobalConfig config = new GlobalConfig(); config.NetworkEventAvailable = ReceiveCallback;

//.... }

void Update() { int recConnectionId = 0; int recChannelId = -1; var recArray = new byte[1400]; int recSize = 0; byte error; if (receiveCallbackNew != receiveCallbackOld) { receiveCallbackNew = receiveCallbackOld; var networkEvent = NetworkTransport.ReceiveFromHost(recHostId, out recConnectionId, out recChannelId, recArray, (ushort)recArray.Length, out recSize, out error); Debug.Assert(networkEvent != NetworkEventType.Nothing); } } }

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