diff --git a/Assets/NetworkLobbyClient/Runtime/LobbyClient.dll b/Assets/NetworkLobbyClient/Runtime/LobbyClient.dll index 623717f..0e02e81 100644 Binary files a/Assets/NetworkLobbyClient/Runtime/LobbyClient.dll and b/Assets/NetworkLobbyClient/Runtime/LobbyClient.dll differ diff --git a/LobbyClient/DirectConnectionResultTest.cs b/LobbyClient/DirectConnectionResultTest.cs index 407862a..93451f2 100644 --- a/LobbyClient/DirectConnectionResultTest.cs +++ b/LobbyClient/DirectConnectionResultTest.cs @@ -13,5 +13,10 @@ namespace Lobbies /// The ip address the connection succeeded on /// public IPAddress? IPAddress { get; internal set; } + + /// + /// If failed contains a error message reason + /// + public string? ErrorMessage { get; internal set; } } } diff --git a/LobbyClient/LobbyClient.cs b/LobbyClient/LobbyClient.cs index 5b05b42..b172cff 100644 --- a/LobbyClient/LobbyClient.cs +++ b/LobbyClient/LobbyClient.cs @@ -278,32 +278,41 @@ namespace Lobbies { return Task.Run(() => { + string? error = string.Empty; IPAddress? ret = null; - using(var waitForIpEvent = new AutoResetEvent(false)) - using (var udpEchoClient = new UdpEchoServer()) - { - udpEchoClient.Reached += (ep) => + try + { + using (var waitForIpEvent = new AutoResetEvent(false)) + using (var udpEchoClient = new UdpEchoServer()) { - ret = ep.Address; - try + udpEchoClient.Reached += (ep) => { - waitForIpEvent.Set(); - udpEchoClient.Stop(); + ret = ep.Address; + try + { + waitForIpEvent.Set(); + udpEchoClient.Stop(); + } + catch { } + }; + + udpEchoClient.Start(0); + + foreach (var ip in ipAddressesToTry) + { + udpEchoClient.CheckConnectionPossible(new IPEndPoint(ip, tryPort)); } - catch { } - }; - udpEchoClient.Start(0); - - foreach (var ip in ipAddressesToTry) - { - udpEchoClient.CheckConnectionPossible(new IPEndPoint(ip, tryPort)); + if(!waitForIpEvent.WaitOne(500)) + error = $"Timeout"; } - - waitForIpEvent.WaitOne(500); + } + catch (Exception ex) + { + error = $"Exception: {ex}"; } - events.Enqueue(new LobbyClientEvent { EventType = LobbyClientEventTypes.DirectConnectionTestComplete, EventData = new DirectConnectionTestResult { DirectConnectionPossible = ret != null, IPAddress = ret } }); + events.Enqueue(new LobbyClientEvent { EventType = LobbyClientEventTypes.DirectConnectionTestComplete, EventData = new DirectConnectionTestResult { DirectConnectionPossible = ret != null, IPAddress = ret, ErrorMessage = error } }); }); }