Version: 2019.2
Method group is Obsolete

ConnectionConfig.ConnectTimeout

Switch to Manual
Obsolete public uint ConnectTimeout ;

Description

Timeout in ms which library will wait before it will send another connection request.

using UnityEngine;
using UnityEngine.Networking;

public class ExampleScript : MonoBehaviour { int m_MyHostId; int m_PeerId;

void Init() { ConnectionConfig myConfig = new ConnectionConfig(); myConfig.AddChannel(QosType.Unreliable); myConfig.AddChannel(QosType.UnreliableFragmented); myConfig.ConnectTimeout = 1000; myConfig.MaxConnectionAttempt = 5;

HostTopology myTopology = new HostTopology(myConfig, 10); //up to 10 connection allowed m_MyHostId = NetworkTransport.AddHost(myTopology, 9999); }

public void Connect() { byte error = (byte)NetworkError.Ok; m_PeerId = NetworkTransport.Connect(m_MyHostId, "127.0.0.1", 9999, 0, out error); }

void Update() { byte error = (byte)NetworkError.Ok; if ((NetworkError)error != NetworkError.Ok) { Debug.LogError("Network error is occurred: " + (NetworkError)error); } else { int recHostId; int connectionId; int channelId; byte[] recBuffer = new byte[1024]; int bufferSize = 1024; int dataSize; bool done = false; while (!done) { NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error); switch (recData) { case NetworkEventType.Nothing: //1 break; case NetworkEventType.ConnectEvent: //2 Debug.Assert(connectionId == m_PeerId, "success"); done = false; break; case NetworkEventType.DataEvent: //3 break; case NetworkEventType.DisconnectEvent: //4 Debug.Assert(connectionId == m_PeerId, "fail"); done = false; break; } } } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961