Fixed non catched exception
parent
cee5a4cf4f
commit
9a25ee86e8
Binary file not shown.
|
|
@ -13,5 +13,10 @@ namespace Lobbies
|
||||||
/// The ip address the connection succeeded on
|
/// The ip address the connection succeeded on
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IPAddress? IPAddress { get; internal set; }
|
public IPAddress? IPAddress { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If failed contains a error message reason
|
||||||
|
/// </summary>
|
||||||
|
public string? ErrorMessage { get; internal set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -278,32 +278,41 @@ namespace Lobbies
|
||||||
{
|
{
|
||||||
return Task.Run(() =>
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
|
string? error = string.Empty;
|
||||||
IPAddress? ret = null;
|
IPAddress? ret = null;
|
||||||
using(var waitForIpEvent = new AutoResetEvent(false))
|
try
|
||||||
using (var udpEchoClient = new UdpEchoServer())
|
{
|
||||||
{
|
using (var waitForIpEvent = new AutoResetEvent(false))
|
||||||
udpEchoClient.Reached += (ep) =>
|
using (var udpEchoClient = new UdpEchoServer())
|
||||||
{
|
{
|
||||||
ret = ep.Address;
|
udpEchoClient.Reached += (ep) =>
|
||||||
try
|
|
||||||
{
|
{
|
||||||
waitForIpEvent.Set();
|
ret = ep.Address;
|
||||||
udpEchoClient.Stop();
|
try
|
||||||
|
{
|
||||||
|
waitForIpEvent.Set();
|
||||||
|
udpEchoClient.Stop();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
};
|
||||||
|
|
||||||
|
udpEchoClient.Start(0);
|
||||||
|
|
||||||
|
foreach (var ip in ipAddressesToTry)
|
||||||
|
{
|
||||||
|
udpEchoClient.CheckConnectionPossible(new IPEndPoint(ip, tryPort));
|
||||||
}
|
}
|
||||||
catch { }
|
|
||||||
};
|
|
||||||
|
|
||||||
udpEchoClient.Start(0);
|
if(!waitForIpEvent.WaitOne(500))
|
||||||
|
error = $"Timeout";
|
||||||
foreach (var ip in ipAddressesToTry)
|
|
||||||
{
|
|
||||||
udpEchoClient.CheckConnectionPossible(new IPEndPoint(ip, tryPort));
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
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 } });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue