Skip to content

Commit a0fb9b3

Browse files
committed
Add support for connecting via a hostname instead of IP when using supported versions of unity and unity transport.
1 parent c1f9445 commit a0fb9b3

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,7 @@ private static NetworkEndpoint ParseNetworkEndpoint(string ip, ushort port, bool
256256
if (!NetworkEndpoint.TryParse(ip, port, out endpoint, NetworkFamily.Ipv4) &&
257257
!NetworkEndpoint.TryParse(ip, port, out endpoint, NetworkFamily.Ipv6))
258258
{
259-
if (!silent)
260-
{
261-
Debug.LogError($"Invalid network endpoint: {ip}:{port}.");
262-
}
259+
return default;
263260
}
264261

265262
return endpoint;
@@ -512,8 +509,15 @@ private bool ClientBindAndConnect()
512509
// Verify the endpoint is valid before proceeding
513510
if (serverEndpoint.Family == NetworkFamily.Invalid)
514511
{
512+
#if HOSTNAME_RESOLUTION_AVAILABLE && UTP_TRANSPORT_2_4_ABOVE
513+
// If it's not valid, try to treat it like a URL.
514+
InitDriver();
515+
m_Driver.Connect(ConnectionData.Address, ConnectionData.Port);
516+
return true;
517+
#else
515518
Debug.LogError($"Target server network address ({ConnectionData.Address}) is {nameof(NetworkFamily.Invalid)}!");
516519
return false;
520+
#endif
517521
}
518522

519523
InitDriver();
@@ -625,7 +629,7 @@ public void SetClientRelayData(string ipAddress, ushort port, byte[] allocationI
625629
/// <summary>
626630
/// Sets IP and Port information. This will be ignored if using the Unity Relay and you should call <see cref="SetRelayServerData"/>
627631
/// </summary>
628-
/// <param name="ipv4Address">The remote IP address (despite the name, can be an IPv6 address)</param>
632+
/// <param name="ipv4Address">The remote IP address (despite the name, can be an IPv6 address or a domain name)</param>
629633
/// <param name="port">The remote port</param>
630634
/// <param name="listenAddress">The local listen address</param>
631635
public void SetConnectionData(string ipv4Address, ushort port, string listenAddress = null)

com.unity.netcode.gameobjects/Runtime/com.unity.netcode.runtime.asmdef

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@
6767
"name": "Unity",
6868
"expression": "6000.0.11f1",
6969
"define": "COM_UNITY_MODULES_PHYSICS2D_LINEAR"
70+
},
71+
{
72+
"name": "com.unity.transport",
73+
"expression": "2.4.0",
74+
"define": "UTP_TRANSPORT_2_4_ABOVE"
75+
},
76+
{
77+
"name": "Unity",
78+
"expression": "6000.1.0a1",
79+
"define": "HOSTNAME_RESOLUTION_AVAILABLE"
7080
}
7181
],
7282
"noEngineReferences": false

0 commit comments

Comments
 (0)