mirror of
https://gitlab1.ptb.de/waltem01/csharpsocketserver
synced 2024-02-04 23:19:43 +00:00
dns resolve and bugfixes
This commit is contained in:
parent
b6a0e4e9a5
commit
1d64ee823a
16
SocketLib.cs
16
SocketLib.cs
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user