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.

ConnectionConfig.MaxConnectionAttempt

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 MaxConnectionAttempt: byte;
public byte MaxConnectionAttempt;

Description

Defines the maximum number of times Unity Multiplayer will attempt to send a connection request without receiving a response before it reports that it cannot establish a connection. Default value = 10.

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

public class ExampleScript : NetworkBehaviour { 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; } } } } }

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