dns resolve and bugfixes

This commit is contained in:
waltem01 2022-07-04 13:11:39 +02:00
parent b6a0e4e9a5
commit 1d64ee823a

View File

@ -62,6 +62,19 @@ public static class Connection {
if (ipAndPort != "") {
string[] splits = ipAndPort.Split(':');
ipAddr = splits[0];
try {
IPAddress.Parse(ipAddr);
} catch (Exception) {
IPHostEntry entryList = Dns.GetHostEntry(ipAddr);
IPAddress? ipv4Entry = null;
foreach (IPAddress entry in entryList.AddressList)
if (entry.AddressFamily == AddressFamily.InterNetwork) {
ipv4Entry = entry;
break;
}
if (ipv4Entry != null)
ipAddr = ipv4Entry.ToString();
}
_port = int.Parse(splits[1]);
}
@ -112,7 +125,8 @@ public static class Connection {
other.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), other);
} catch (Exception) {
// Close client connection
disconnectMethod.Invoke(other);
if (disconnectMethod != null)
disconnectMethod.Invoke(other);
other.Close();
}
}