From 21a1fa46254f3b42abebcc60fcc920f086f79bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Chrobot?= Date: Thu, 23 Apr 2026 15:27:19 +0200 Subject: [PATCH 1/3] Re-enabled ConnectSingleClient_Hostname test --- .../Tests/Runtime/Transports/UnityTransportConnectionTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/Transports/UnityTransportConnectionTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/Transports/UnityTransportConnectionTests.cs index 7ab2df5f03..92e4beb906 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/Transports/UnityTransportConnectionTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/Transports/UnityTransportConnectionTests.cs @@ -132,7 +132,6 @@ public IEnumerator ConnectSingleClient_WebSocket_IPAddressAndPath() #if HOSTNAME_RESOLUTION_AVAILABLE // Check connection with a single client (hostname). [UnityTest] - [UnityPlatform(exclude = new[] { RuntimePlatform.Android })] // Test fails on Android for editors 6000.3+ Tracked in MTT-14757 public IEnumerator ConnectSingleClient_Hostname() { InitializeTransport(out m_Server, out m_ServerEvents); From 4f757a7929d2410d1978f271492448abb8b645c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Chrobot?= Date: Thu, 23 Apr 2026 21:38:06 +0200 Subject: [PATCH 2/3] Potentiall fix to Hostname resolution issue --- .../UnityTransportConnectionTests.cs | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/Transports/UnityTransportConnectionTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/Transports/UnityTransportConnectionTests.cs index 92e4beb906..69ca168168 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/Transports/UnityTransportConnectionTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/Transports/UnityTransportConnectionTests.cs @@ -137,9 +137,10 @@ public IEnumerator ConnectSingleClient_Hostname() InitializeTransport(out m_Server, out m_ServerEvents); InitializeTransport(out m_Clients[0], out m_ClientsEvents[0]); - // We don't know if localhost will resolve to 127.0.0.1 or ::1, so we wait until we know - // before starting the server. Because localhost is pretty much always defined locally - // it should resolve immediatly and thus waiting one frame should be enough. + // We don't know if localhost will resolve to 127.0.0.1 or ::1 (or even a device LAN + // IP on some Android versions), so we wait until we know before starting the server. + // We poll until GetLocalEndpoint() returns a valid endpoint rather than assuming one + // frame is always enough — resolution may span multiple driver updates on some platforms. // We'll need to retry connection requests most likely so make this fast. m_Clients[0].ConnectTimeoutMS = 50; @@ -147,11 +148,23 @@ public IEnumerator ConnectSingleClient_Hostname() m_Clients[0].SetConnectionData("localhost", 7777); m_Clients[0].StartClient(); - yield return null; + // Wait until hostname resolution has completed and the driver has bound. + // On some Android devices "localhost" can resolve to the device's LAN IP rather than + // a loopback address, so we use the actual resolved address instead of hardcoding + // "127.0.0.1" or "::1" based solely on the address family. + NetworkEndpoint endpoint; + var resolutionDeadline = Time.realtimeSinceStartup + 2f; + do + { + yield return null; + endpoint = m_Clients[0].GetLocalEndpoint(); + } while (endpoint.Family == NetworkFamily.Invalid && + Time.realtimeSinceStartup < resolutionDeadline); + + Assert.AreNotEqual(NetworkFamily.Invalid, endpoint.Family, + "Timed out waiting for localhost hostname resolution to complete."); - var endpoint = m_Clients[0].GetLocalEndpoint(); - var ip = endpoint.Family == NetworkFamily.Ipv4 ? "127.0.0.1" : "::1"; - m_Server.SetConnectionData(ip, 7777, ip); + m_Server.SetConnectionData(endpoint.Address, 7777, endpoint.Address); m_Server.StartServer(); yield return WaitForNetworkEvent(NetworkEvent.Connect, m_ClientsEvents[0]); From a9f3c802e44f5e1ce45128cb08d1334cfdd10741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Chrobot?= Date: Fri, 24 Apr 2026 11:25:49 +0200 Subject: [PATCH 3/3] connection test --- .../Runtime/Transports/UnityTransportConnectionTests.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/Transports/UnityTransportConnectionTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/Transports/UnityTransportConnectionTests.cs index 69ca168168..abbfcad948 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/Transports/UnityTransportConnectionTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/Transports/UnityTransportConnectionTests.cs @@ -164,7 +164,12 @@ public IEnumerator ConnectSingleClient_Hostname() Assert.AreNotEqual(NetworkFamily.Invalid, endpoint.Family, "Timed out waiting for localhost hostname resolution to complete."); - m_Server.SetConnectionData(endpoint.Address, 7777, endpoint.Address); + // Use the wildcard listen address for the resolved address family. This handles + // cases where "localhost" resolves to a non-loopback address (e.g. a device's LAN + // IP on some Android versions) and avoids relying on the exact IP in the local + // endpoint (which may be a wildcard 0.0.0.0 when UTP binds before routing). + var listenAddress = endpoint.Family == NetworkFamily.Ipv6 ? "::" : "0.0.0.0"; + m_Server.SetConnectionData(listenAddress, 7777, listenAddress); m_Server.StartServer(); yield return WaitForNetworkEvent(NetworkEvent.Connect, m_ClientsEvents[0]);