fix(dotnet): support IP address server names

This commit is contained in:
Benoît CORTIER
2024-04-09 11:35:48 -04:00
committed by Benoît Cortier
parent a18fb34b6d
commit 26421c7469
@@ -197,8 +197,15 @@ public class Connection
static async Task<NetworkStream> CreateTcpConnection(String servername, int port)
{
IPHostEntry ipHostInfo = await Dns.GetHostEntryAsync(servername);
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPAddress ipAddress;
try {
ipAddress = IPAddress.Parse(servername);
} catch (FormatException) {
IPHostEntry ipHostInfo = await Dns.GetHostEntryAsync(servername);
ipAddress = ipHostInfo.AddressList[0];
}
IPEndPoint ipEndPoint = new(ipAddress, port);
TcpClient client = new TcpClient();
@@ -220,4 +227,4 @@ public static class Utils
vecU8.Fill(buffer);
return buffer;
}
}
}