diff --git a/Assets/Mirror/Components/Discovery/NetworkDiscovery.cs b/Assets/Mirror/Components/Discovery/NetworkDiscovery.cs index 5d9008733..ce6b8a0c8 100644 --- a/Assets/Mirror/Components/Discovery/NetworkDiscovery.cs +++ b/Assets/Mirror/Components/Discovery/NetworkDiscovery.cs @@ -59,7 +59,7 @@ protected override ServerResponse ProcessRequest(ServerRequest request, IPEndPoi return new ServerResponse { serverId = ServerId, - uri = transport.ServerUri() + address = transport.ServerAddress() }; } catch (NotImplementedException) @@ -98,13 +98,19 @@ protected override void ProcessResponse(ServerResponse response, IPEndPoint endp // although we got a supposedly valid url, we may not be able to resolve // the provided host + // TODO Y THO??????? // However we know the real ip address of the server because we just // received a packet from it, so use that as host. - UriBuilder realUri = new UriBuilder(response.uri) + // UriBuilder realUri = new UriBuilder(response.uri) + // { + // Host = response.EndPoint.Address.ToString() + // }; + // response.uri = realUri.Uri; + + if (Utils.ParseHostAndPort(response.address, out string _, out ushort port)) { - Host = response.EndPoint.Address.ToString() - }; - response.uri = realUri.Uri; + response.address = $"{response.EndPoint.Address}:{port}"; + } OnServerFound.Invoke(response); } diff --git a/Assets/Mirror/Components/Discovery/ServerResponse.cs b/Assets/Mirror/Components/Discovery/ServerResponse.cs index 746578376..08e93f1dd 100644 --- a/Assets/Mirror/Components/Discovery/ServerResponse.cs +++ b/Assets/Mirror/Components/Discovery/ServerResponse.cs @@ -1,5 +1,4 @@ -using System; -using System.Net; +using System.Net; namespace Mirror.Discovery { @@ -10,9 +9,10 @@ public struct ServerResponse : NetworkMessage // client fills this up after we receive it public IPEndPoint EndPoint { get; set; } - public Uri uri; + // Transport.ServerAddress(). can be "IP:Port". + public string address; // Prevent duplicate server appearance when a connection can be made via LAN on multiple NICs public long serverId; } -} \ No newline at end of file +}